From: Olivier Andrieu MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-ID: <16231.2269.152007.823440 at karryall.dnsalias.org> Date: Tue, 16 Sep 2003 14:58:05 +0200 To: Richard Jones Cc: lablgtk at kaba.or.jp Subject: Re: Memory handling bug: cannot access fields in a combo box belonging to a dialog which has been destroyed In-Reply-To: <20030916103137.GA25181 at redhat.com> References: <20030916103137.GA25181 at redhat.com> Hi Richard, Richard Jones [Tuesday 16 September 2003] : > The following program demonstrates a bug (I think) in the memory > handling of lablgtk2 (tested against lablgtk2-20030828 on Linux and > Windows). > > The program creates a dialog containing a combo box, then destroys > the dialog, and tries to retrieve the text from the combo box. > > This fails with the following Gtk error: > > Fatal error: exception Glib.Critical("GLib-GObject", "file > gobject.c: line 1319 (g_object_ref): assertion `G_IS_OBJECT > (object)' failed") > > and the program aborts. > > The entry widget in the combo box shouldn't, of course, be deleted > until all references held by the program have been destroyed. But the (caml) program _doesn't_ hold a reference on the entry until you've called combo#entry. Here's what happening : you're calling destroy on the dialog (through the GtkButton::clicked callback), so the dialog is destroyed and in the process recursively destroys all its children. The combo is destroyed, and its refcount drops at one (the caml reference). However, the combo destroyed its children, including the text entry. The latter had a refcount of one (held by the combo), so its memory was released. If you want to use the entry afterwards, you have to increase its refcount by transfering it on the caml side. In your test program the fix is very easy, use : let entry = (GEdit.combo .... ()) # entry in -- Olivier