Huge memory leak each time set_menu is used

Bug #717529 reported by Michael Judge
This bug report is a duplicate of:  Bug #569273: memory leak in gnome-power-manager. Edit Remove
10
This bug affects 2 people
Affects Status Importance Assigned to Milestone
indicator-application (Ubuntu)
Incomplete
Low
Unassigned

Bug Description

Binary package hint: indicator-application

It seems that there is a memory leak whenever set_menu() is called to generate an indicator menu. I have written an RSS feed reading program that re-creates the menu at a timed interval. Memory usage increases by up to 3-4Mb whenever set_menu() is called. I have run the script with just set_menu() commented out, and there is no increase in memory usage.

I have python-appindicator version 0.0.19-0ubuntu4 in Lucid although I believe it applies to newer versions too, such as the one in Maverick.

Further discussion of the issue here:
http://code.google.com/p/feedindicator/issues/detail?id=10

One commenter submitted a test script which demonstrates the memory increasing over time:

# MEMORY LEAK TEST SCRIPT

#!/usr/bin/env python

import gtk, gobject, appindicator, time, glib

def refresh():
        global ind
        global menu
        print("updating")
        for menu_item in menu.get_children():
                menu.remove(menu_item)
                menu_item.destroy()
        for i in range(0,20):
                menu_item = gtk.MenuItem("item "+str(i))
                menu_item.show()
                menu.append(menu_item)
        ind.set_menu(menu)
        return 1

ind = appindicator.Indicator ("bug-test","indicator-messages-new", appindicator.CATEGORY_COMMUNICATIONS)
ind.set_status (appindicator.STATUS_ACTIVE)

menu = gtk.Menu()
ind.set_menu(menu)

glib.timeout_add_seconds(2, refresh)
gtk.main()

description: updated
Jim Bauwens (jimbauwens)
Changed in indicator-application (Ubuntu):
status: New → Incomplete
status: Incomplete → New
Revision history for this message
Jim Bauwens (jimbauwens) wrote :

Ops, sorry for that, press the wrong button :)

I am the commenter that submitted the test case above.
The problem effect both Lucid and Maverick, and is real annoying, as it cripples programs that need a constant updating menu.
I've tried many different things to bypass this memory leak, but even removing the app indicator doesn't free the memory.
So I would really appreciate it if someone would find a solution to this problem :)

Thanks,
Jim

Revision history for this message
Sebastien Bacher (seb128) wrote : Re: small memory leak each time set_menu is used

Running the example with the current version shows a very small usage increase over time, the issue seems mostly fixed, updating the title since it might still be worth checking if there is still a small leak somewhere

summary: - Large memory leak each time set_menu is used
+ small memory leak each time set_menu is used
Changed in indicator-application (Ubuntu):
importance: Undecided → Low
Revision history for this message
Jim Bauwens (jimbauwens) wrote :

Sorry for the late reply, but for some reason I was not subscribed to this post.

I have tested the above code on my fully updated 10.10 32 bit system, and I still have the problem.
The memory raises with 2-4 MiB every update.

So I guess that this bug is still important.

Revision history for this message
Jim Bauwens (jimbauwens) wrote :

I changed the title, this bug is STILL valid. I'm unable to program with indicators in python because of this.
Look at http://code.google.com/p/feedindicator/issues/detail?id=10 for the bug in real life.

summary: - small memory leak each time set_menu is used
+ Huge memory leak each time set_menu is used
Revision history for this message
Michael Terry (mterry) wrote :

Jim, have you seen bug 569273? For maverick, try manually unref'ing the menu after set_menu. In natty, you won't have to, as that particular bug was fixed. If you can confirm that manually unref'ing the menu fixes the leak, I'll close this as a duplicate.

So add something like:

menu.unref()

after the set_menu call.

Changed in indicator-application (Ubuntu):
status: New → Incomplete
Revision history for this message
Jim Bauwens (jimbauwens) wrote :

Its looks like there is no unref method in the python version ...

>>> dir(appindicator.Indicator)
['__class__', '__cmp__', '__copy__', '__deepcopy__', '__delattr__', '__dict__', '__doc__', '__format__', '__gdoc__', '__getattribute__', '__gobject_init__', '__grefcount__', '__gtype__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'chain', 'connect', 'connect_after', 'connect_object', 'connect_object_after', 'disconnect', 'disconnect_by_func', 'emit', 'emit_stop_by_name', 'freeze_notify', 'get_attention_icon', 'get_category', 'get_data', 'get_icon', 'get_icon_theme_path', 'get_id', 'get_label', 'get_label_guide', 'get_ordering_index', 'get_properties', 'get_property', 'get_status', 'handler_block', 'handler_block_by_func', 'handler_disconnect', 'handler_is_connected', 'handler_unblock', 'handler_unblock_by_func', 'notify', 'props', 'set_attention_icon', 'set_data', 'set_icon', 'set_icon_theme_path', 'set_label', 'set_menu', 'set_ordering_index', 'set_properties', 'set_property', 'set_status', 'stop_emission', 'thaw_notify', 'weak_ref']

There is weak_ref, but I think that is something else.
Anyway, thanks for giving the link to the other bug, I'm glad to see it is fixed! Good work :)

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.