Cycle detection and object memory usage?

J

Jim Kleckner

cycles:

I understand from the documentation that types with a finalizer method
that participate in cycles can't be collected.

What is the best way to go about finding these cycles?
Googling gives a variety of methods none of which seem terribly
mainstream for such a common problem.


Object memory usage:

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.

Thanks.
 
J

John Nagle

Jim said:
cycles:

I understand from the documentation that types with a finalizer method
that participate in cycles can't be collected.

What is the best way to go about finding these cycles?
Googling gives a variety of methods none of which seem terribly
mainstream for such a common problem.

Put the Python garbage collector into debug mode and find out
what it reports as non-collectable.

Use weak pointers where appropriate to avoid cycles.
The general idea is that pointers back towards the root
of a tree structure should be weak pointers, which will
result in a cycle-free structure. I put that in BeautifulSoup,
and it works quite well.

John Nagle
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,731
Messages
2,569,432
Members
44,832
Latest member
GlennSmall

Latest Threads

Top