#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2004
    Posts
    1
    Rep Power
    0

    memory debugging


    Hi,
    I have developed a rather large program in python that leaks memory somewhere. However I have no idea where. Does anyone know of tools that can help with finding memory leaks in python?
    Alternatively is there some way to query the amount of memory a program uses from within python?

    Thanks in advance,
    Frederik Fix
  2. #2
  3. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    I've never had much a problem with memory leaks in Python and have only got a MemoryError once in the time i've used it so Python seems to be pretty good at limiting this. In any case manybe these likes will help:

    http://www.nightmare.com/medusa/memory-leaks.html
    http://zope.org/Members/mcdonc/HowTo...dDebugMemLeaks - Python and Zope

    You might also like to check out pythons profiler modules although i'm not sure if they show memory usage or not...

    http://www.python.org/doc/2.3.3/lib/module-profile.html
    http://www.python.org/doc/2.3.3/lib/module-hotshot.html

    But if you fire up your browser and search google a little i'm sure you'll be able to find what your looking for .

    Hope this is of some help,

    Mark.
    Last edited by netytan; March 26th, 2004 at 10:59 AM.
    programming language development: www.netytan.com Hula

  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Feb 2004
    Location
    London, England
    Posts
    1,585
    Rep Power
    1373
    If you are using a modern version of Python that has been compiled with garbage collection enabled, then you can use the 'gc' module in the standard library to get information about the objects known to the garbage collector, force garbage collection, trace object creation and deletion, etc. RTFM for full information.


    For earlier versions of Python there is a tool called Cyclops written by Python Guru Tim Peters. This tracks down and reports cyclic object references. It is rather dated (1999) but should still work with current versions of Python. You can find it on the Python.org FTP server - http://www.python.org/ftp/python/con...c-1999/System/. There may be more recent versions around, but I have not found any. If garbage collection is enabled then cycles should not be such a problem unless an object cannot be freed by the GC.

    There is also a function in the sys module 'getrefcount' that you can use to find out how many reference there are to an object.

    Between these three, you should be able to track down any leaks in your Python code. Leaks in extension modules is another matter.

    Hope this helps,

    Dave - The Developers' Coach
    Last edited by DevCoach; March 26th, 2004 at 11:42 AM.

IMN logo majestic logo threadwatch logo seochat tools logo