Cycle detection and object memory usage?

Discussion in 'Python' started by Jim Kleckner, May 21, 2007.

  1. Jim Kleckner

    Jim Kleckner Guest

    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.
    Jim Kleckner, May 21, 2007
    #1
    1. Advertising

  2. Jim Kleckner

    John Nagle Guest

    Jim Kleckner wrote:
    > 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
    John Nagle, May 21, 2007
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. metfan
    Replies:
    2
    Views:
    4,847
    Robert Olofsson
    Oct 21, 2003
  2. hvt
    Replies:
    0
    Views:
    1,207
  3. hvt
    Replies:
    0
    Views:
    1,465
  4. Replies:
    2
    Views:
    979
    bugbear
    May 3, 2007
  5. Krist
    Replies:
    8
    Views:
    6,423
    Arne Vajhøj
    Feb 10, 2010
Loading...

Share This Page