Cycle detection and object memory usage?

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Tue May 22 04:00:50 EDT 2007


En Mon, 21 May 2007 22:15:14 -0300, Jim Kleckner <jek-gmane at kleckner.net>  
escribió:

> Gabriel Genellina wrote:
>> En Sun, 20 May 2007 23:54:15 -0300, Jim Kleckner  
>> <jek-gmane at kleckner.net>
>> escribió:
>>
>>> What is the best way to go about finding these cycles?
>>
>> Avoid them in the first place :)
>> Use the gc module: after a call to gc.collect(), see if something  
>> remains in gc.garbage
>
> I would have sworn that there were uncollectable objects when I
> tried this before.  Now they don't show up.  I guess that is good...

(... or bad, it you actually know that you have a problem but you cant  
reproduce it).

>>> Has anyone written a function to sweep out an object to discover how
>>> much memory it and all the objects it references is using?  This would
>>> be great for performance tuning.
>>
>> A rough estimate may be the object's pickle size. But it's hard to  
>> measure precisely; by example, strings are immutable and you may have  
>> thousands of shared references to the same string, and they require  
>> just a few bytes
>> each.
>
> Good idea, thanks.
> I take it then that memory profiling isn't available?

I don't know of any tool - maybe because I've never needed one until now.

-- 
Gabriel Genellina




More information about the Python-list mailing list