[Tutor] python memory management

Alan Gauld alan.gauld at yahoo.co.uk
Thu Sep 1 12:57:01 EDT 2016


On 01/09/16 15:12, monikajg at netzero.net wrote:
> Can somebody please explain how memory is managed by python? 
> What kind of memory it uses? What structures use what kind of memory?

I'm not sure what you have in mind?
Do you want to know the internal structure of the various data types? Do
you want to know the size of the memory footprint?

> If many people work on the same project and have many 
> instances of the same object how do they ensure that
> all instances are killed before the programs exit? 

Generally each developer runs their own instance of the
program and the OS/Python manage the memory for each
process entirely separate from all other processes.

> Apparently if one of the programmer leaves a reference 
> to object it might not be automatically deleted
> by python on exit. What is the command to do this?

When python exits, all objects are deleted regardless
of how many references still exist. The issue is more
relevant to a server process which never exits. In that
case it is possible for a programmer to leave a
reference to an obsolete object and prevent it
from being disposed of. This is known as a memory
leak. But the issue applies just as much to a single
programmer as to multiple programmers. It is a design
issue that requires that the redundant objects are
cleared away correctly with no dangling references.
It is one of the many design considerations when
building long running code.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos




More information about the Tutor mailing list