Memory deallocation

Steven D'Aprano steven at REMOVE.THIS.cybersource.com.au
Mon Oct 19 09:54:34 CEST 2009


On Mon, 19 Oct 2009 00:30:30 -0700, dheeraj wrote:

> Hi, a program of mine is being terminated by the OS as it uses too much
> memory. I guess this is due to static memory allocation
> 
> I've also tried to use "del" but in vain. Is there any other function
> that performs the above operation and frees the allocated memory??


Python uses a ref-counting garbage collector which automatically frees 
memory when the number of references to each object falls to zero. This 
is automatic and fast, but it is defeated if you store objects in cycles 
(e.g. x refers to y, and y refers to x) or if you put everything in 
globals which never go out of scope.

In addition Python has a separate garbage collect which can detect, and 
break, many cycles. Perhaps you can use the gc module to debug your 
problem?

I would expect in general that Python will fail with a MemoryError 
exception before the operating system terminates the process for using 
too much memory. What are you doing in your program? What version of 
Python are you using and what OS? You need to give more information for 
us to be more helpful.



-- 
Steven



More information about the Python-list mailing list