[Gtk-sharp-list] Custom widgets are not being collected by the GC

Lluis Sanchez lluis@ximian.com
Sat, 29 Jan 2005 19:49:28 +0100

The following method from Gtk.Widget is a source of memory leaks:

protected override void CreateNativeObject (string[] names, GLib.Value[]
	base.CreateNativeObject (names, vals);
	ParentSet += new ParentSetHandler (Widget_ParentSet);

because the ParentSet event is never unsubscribed. The ParentSetHandler
delegate holds a reference to "this" widget, and the delegate is kept
forever in a global Hashtable in SignalCallback. The result is that
custom widgets (which callCreateNativeObject) are never collected.

This case could be fixed by somehow moving the code for Widget_ParentSet
to the OnParentSet method and avoid using the event. I don't know if
this can be done with the api generator.

However, in general, with the current design any widget that subscribes
its own events will never be GCed.