RE: [java-gnome-hackers] Widget ref and unref
Brought to you by:
afcowie
From: Mark H. <mh...@ti...> - 2002-09-03 17:51:25
|
On Tue, 2002-09-03 at 14:25, Jeffrey Morgan wrote: > Can we take a step back and discuss the root problem > we are trying to solve with the ref and unref? There=20 > might be other solutions to the problem. AFAIK:=20 Gtk frees objects when it thinks they are done with. One consequence of this is that it is currently impossible in Java-gnome to remove a widget from a table and the put the widget back into the table at a later time. To make gtk know that the widgets are not finished with, the=20 gtk_widget_ref or g_object_ref methods should be called To allow the object to be freed, a call has to be made to gtk_widget_unref or g_object_unref Java developers won't expect a widget to disappear when the Java object for it still exists. so, IMHO, we need to 'ref each widget as it is created and unref it when the java object is destroyed (gtk will not free the object until there are no internal gtk references to it (e.g. as part of another widget) and the unref has been made). My original way of doing this was to add the ref to the initialiseEventHandlers method, as this is called whenever an object is instantiated; and add the unref to a finally clause. This has the problem that finally is not guaranteed to be called.=20 I guess (but don't know) that gtk will free the object regardless when it is asked to finish, so the only problem would be while the program is running. If not, the OS should clear up on exit, but that's not a good way to do it. --=20 +----------------------------------------------+ | Mark Howard cam.ac.uk mh344@ | | http://www.tildemh.com tildemh.com mh@ | +----------------------------------------------+ |