Re: Problems with un-owned objects passed to closures in pygobject (gtk_cell_renderer_text_start_editing)
- From: Simon Feltman <s feltman gmail com>
- To: Tristan Van Berkom <tvb gnome org>
- Cc: gtk-devel-list gnome org
- Subject: Re: Problems with un-owned objects passed to closures in pygobject (gtk_cell_renderer_text_start_editing)
- Date: Sun, 3 Feb 2013 18:39:20 -0800
After some deliberation and writing a bunch of tests:
http://git.gnome.org/browse/pygobject/commit/?id=97f48f
I am starting to warm up to an idea where we simply never sink objects and always follow the rules entailed by ownership transference annotations already in place, with one caveat: g_object_new is annotated as transfer full but can also return floating references. In this case, we must check the returned type and not believe the annotation when it returns InitiallyUnowned instances, but instead treat it like transfer none and add a new ref.
The reason I think this will work is because libraries that make use of InitiallyUnowned are designed to deal with the floating refs already. Python is basically a thin wrapper used to tie objects together within these systems and never needs to maintain ownership beyond making sure the underlying object is kept alive while the wrapper is alive. From this, we can rely on the internals of the libraries to do the right thing and sink floating references where they normally would in C usage. If they don't, it is most likely a bug in C as well (by convention). This seems like it will solve all of the current problems and special casing during marshaling. However, it also adds a leak for the most basic (and useless) case:
for i in range(10):
Gtk.Button()
This would leak the initial floating ref and the memory would be lost. However, I can't think of a real use case where something like that would ever be needed.
The alternatives to can become grossly convoluted:
Thoughts?
-Simon
[Date Prev][
Date Next] [Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]