Reference Counts & Extensions..

Brian Quinlan BrianQ at ActiveState.com
Tue Jun 12 17:42:37 EDT 2001


Alex wrote:
> > Will this cause a memory leak?  Should I be doing this:
>
> It's probably still prudent to worry about this if you have the
time,
> but I had the impression that with garbage collection in
> python2.0, you
> didn't have to.

You do have to!

The garbage collector in CPython 2.0 will free cyclic memory
references but it cannot free objects whose reference count is simply
too high. How could it? It doesn't have any way of inspecting your C
code to see if you really wanted that object to stay around or if it
is safe to collect it because you lied when incrementing the reference
count.





More information about the Python-list mailing list