[Tutor] Question about the memory manager

Albert-Jan Roskam sjeik_appie at hotmail.com
Sun Jan 10 06:53:22 EST 2016


Hi,

I just found a neat trick to free up an emergency stash of memory in a funtion that overrides sys.excepthook. The rationale is that all exceptions, including MemoryErrors will be logged.
The code is below. My question: is that memory *guaranteed* to be freed right after the 'del' statement? Or should one call gc.collect to be really sure?

rainydayfund = [[] for x in xrange(16*1024)] # or however much you need
def handle_exception(e):
global rainydayfund
del rainydayfund
... etc, etc ...
http://stackoverflow.com/questions/1235349/python-how-can-i-handle-any-unhandled-exception-in-an-alternative-way

Thanks!

Albert-Jan
 		 	   		  


More information about the Tutor mailing list