Wierd behavior of gc.collect
Dave Angel
davea at davea.name
Tue Mar 19 13:13:11 EDT 2013
On 03/19/2013 12:36 PM, Bodhi wrote:
> I know this, but my question is what does gc.collect do which results in the c library to free memory? Usually it is because of unreferenced objects in a cycle or something, but here that doesn't seem to be the case.
>
As I said, python calls the C free() function, whether it's when an
object's ref-count goes to zero, or whether it's during a gc call, where
circular refs are freed.
But free() does not necessarily release the memory to the OS. And the
times it does depends on which C library is being used, and what OS it's
running on.
If the freed memory affects top in some situations, it's a C library
detail. I've written a replacement C allocator in the past for Windows
that used a different scheme for blocks over a certain threshold, and
when those blocks were freed, it gave them back to the OS. But such
blocks were multiples of 64k, which was the increment for VirtualAlloc.
--
DaveA
More information about the Python-list
mailing list