Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python memory limit? Clear GC when close to limit?

How would I clear garbage collected objects before performing other memory intensive operations? Or is it done automatically when the memory is full?

Why does it seem that Python (+Eclipse) throws a Memory Exception at 2 GB (Win32) whereas actually still some memory is unused on Windows? Are there limits defined anywhere?

like image 498
Gerenuk Avatar asked Sep 24 '26 15:09

Gerenuk


2 Answers

You can tweak the performance of the garbage collector with the gc module -- for example, with gc.set_threshold -- or you can "manually" collect the garbage: gc.collect. However, I believe that most of the time, objects are collected as soon as their refcount goes to zero.

So to be explicit about it, (thanks delnan!) garbage collection is only an issue when there are cyclic references that keep refcounts from reaching zero.

Note also this line from the gc docs:

To debug a leaking program call gc.set_debug(gc.DEBUG_LEAK).

like image 119
senderle Avatar answered Sep 26 '26 13:09

senderle


On Windows 32bit Application have a limit of 2GB maximum memory. There a is a boot option that will bump it to 3Gb. You can also try upgrading to 64bit Windows/Python.

like image 33
parapura rajkumar Avatar answered Sep 26 '26 12:09

parapura rajkumar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!