How do you debug memory usage?
Banibrata Dutta
banibrata.dutta at gmail.com
Tue May 6 10:21:15 EDT 2008
Many not be the most intuitive and elegant solution (I'm just a Python
newbie), but if your Python code is constrained to the usage of Python 2.2
language features, you could use Jython, and then (I'm hoping, since I've
not tried this myself), use the Java Memory usage profiling/debugging tools.
Would be really interested to know the answer to the question, i.e. if there
are any CPython solutions.
On Tue, May 6, 2008 at 6:57 PM, David <wizzardx at gmail.com> wrote:
> Hi list.
>
> I've tried Googling for this and I checked the Python docs, but to no
> avail.
>
> What is the best way to debug memory usage in a Python script?
>
> I'd like to see what objects are using the most memory. Ideally this
> would be aware of references too. So if I have a small list that
> contains (references rather) some large variables, then I could see
> that the global list variable was responsible for X MB that couldn't
> be collected by the garbage collector.
>
> It would be nice if it could be used in a similar way to the 'du'
> Linux command. eg:
>
> eg output:
>
> >>> mem_debugger.pretty_print()
> A (type: list): 8 bytes, 10MB
> - a (type: string): 6 MB, 0 bytes
> - b (type: string): 4 MB, 0 bytes
> B (type: dict): 8 bytes, 5 MB
> - d (type: string): 3 MB, 0 bytes
> - c (type: string): 2 MB, 0 bytes
>
> In the output above, the 1st size is the memory used by the object
> itself, and the 2nd size is the memory used by objects it refers to. A
> & B are global vars (a string and a dict), a,b,c, and d are strings
> that were added to A & B at some point in the past, and aren't refered
> to by anything else. Also, the output is in descending order of size.
>
> Are there any tools/modules/etc I can use like this?
>
> David.
> --
> http://mail.python.org/mailman/listinfo/python-list
>
--
regards,
Banibrata
http://www.linkedin.com/in/bdutta
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20080506/4751c931/attachment-0001.html>
More information about the Python-list
mailing list