[sugar] Pygtk and garbage collecting

Robert Staudinger robert.staudinger
Tue Aug 8 12:25:46 EDT 2006


On 8/2/06, Federico Mena Quintero <federico at ximian.com> wrote:

[...]

> The usual idiom  is to have a way to explicitly dispose an object which
> holds a reference to a non-GC resource.  In C# you do
>
>   obj = new SomeObject ();
>   treeview.set_model (obj);
>
>   newobj = new SomeObject ();
>   treeview.set_model (newobj);
>
>   obj.Dispose ();
>
> or use syntactic sugar:
>
>   using (Gdk.Pixbuf pixbuf = new Gdk.Pixbuf ("foo.jpg")) {
>       do_something_with_pixbuf (pixbuf);
>   } /* exiting the "using" block disposes the pixbuf */
>
> This is pretty useful for managed objects which maintain non-managed
> data (file descriptors, memory buffers, database connections, etc.).
>
> Does Python let you do something like this?

It should be possible to export g_object_unref() through the pygobject API.
That would of course be not pythonic at all and not trigger collection
if any other (uncollected) python objects are still holding
references.
(/me waits for pygtk devs to point out more flaws)

- Rob


More information about the Sugar-devel mailing list