[sugar] end of internship
Sat Oct 11 07:00:20 EDT 2008
On Thu, Oct 9, 2008 at 12:12 AM, Federico Mena Quintero
<federico at novell.com> wrote:
> On Tue, 2008-10-07 at 18:26 +0200, Tomeu Vizoso wrote:
>> - Developed a tool for monitoring memory allocation inside the python
>> interpreter. Code:
> Nice, nice, nice! Is this something we could use for the bloaty python
> thingies we have around in GNOME? :)
I think so, but plays a relatively small role in the whole profiling
process. Most important is to remove leaks, that are unfortunately
very common in Pygtk apps.
About leak debugging of Pygtk apps, we have done as follows:
== Look for actions in the UI that result in unbounded allocations ==
Use Riccardo's allocstats module to periodically print allocation
stats, for example in an idle handler or a key event handler.
When you find an UI action that results in net allocation every time
the UI is returned to its previous state, note this UI action as
== Remove all leaks from the python side using Guppy's heapy ==
Connect from another python shell session to the debugged process
using heapy's monitor:
Reset the heap to zero, perform the UI action, then print the heap.
Find a class that makes sense from the application logic POV, then
check why it's being hold in memory. Most probably will be because an
instance belonging to the base state of the app is holding a reference
to it. And the most common cause is because the shorter-lived object
is listening on a signal from the longer-lived object. If the
shorter-lived object is a widget, disconnect those signals in its
destroy signal handler.
== remove all leaks from the C GObject side using refdbg ==
If after removing all leaks from the python side, memory allocations
continue to grow, then we have leaks in the C side, most probably on C
code local to the app, which is presumably less debugged that Pygtk
Get refdbg, and use it as you would do with a normal Gtk app, check
any instances that get referenced more than unreferenced and that
should get released when the UI action finishes but doesn't. Then add
an unref somewhere ;)
Sorry this is so vague and improvised, we should do a proper HOWTO out
of it, but time doesn't abound around here...
More information about the Sugar-devel