Memory deallocation

D

dheeraj

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??

Pls reply
 
S

Steven D'Aprano

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.
 
G

Guest

del is what you should use. You won't see memory reduction for that process,
but the memory will be available for other other objects and prevent a
growth of the memory footprint for that process.

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.

I have seen cases with large dictionaries of large-ish objects where the
machine ends up trashing.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,008
Latest member
HaroldDark

Latest Threads

Top