SiteMap  | About    

Releasing memory in Python

According to Python Official Documentation , you can force the Garbage Collector to release unreferenced memory with gc.collect(). However, one known case where Python will definitely leak memory is when you declare circular references in your object declarations and implement a custom __del__ destructor method in one these classes. Objects referenced from the global namespaces of Python modules are not always deallocated when Python exits. Python's garbage collector (not actually the gc module, which is just the Python interface to the garbage collector) does this. So, Python doesn't detect and free circular memory references before making use of the garbage collector.

Python ordinarily frees most objects as soon as their reference count reaches zero. In the case of circular references , this never happens, so the garbage collector periodically walks memory and frees circularly-referenced objects. Also, it's not possible to forget to free memory such as in C, but it is possible to leave a reference hanging somewhere. Python is, however, aggressive about cleaning up memory on exit and does try to destroy every single object. (C) 2018    Founded by raps mk
All Rights Reserved. All other trademarks are property of their respective owners.