comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Ada newbie  + Gtkada + Win2000 = ?
Date: Sun, 16 Sep 2007 16:53:54 +0200
Date: 2007-09-16T16:52:57+02:00	[thread overview]
Message-ID: <17yxr4b662tt9$.1ki8b1ck4hreq.dlg@40tude.net> (raw)
In-Reply-To: 6h8qe35tkcunqut5ufvjn299om46ku72uh@4ax.com

On Sun, 16 Sep 2007 15:11:06 +0100, Brian Drummond wrote:

> There are two mysteries here: - why the memory leaks occur; the GTK
> documentation claims it manages memory for you, and why it falls over so
> early (even when there is about 500MB of free memory) - if there is some
> heap limit imposed on the program, I can't see it.

Well, GTK does not manage memory. Though, it has a reference counting model
for its objects, it does not provide handles to. The counts need to be
managed manually using Ref, Unref, Sink and Destroy. GtkAda is a thin
binding to GTK+, so it just follows this [IMO, flawed] design.

In effect, when you call Gtk_New the result of is a plain pointer. It is
your responsibility to pass it back to a container type or else explicitly
kill the object. Note also as if that was not enough complicated, GTK has
widgets and other objects. When created both have the reference count 1.
But then for objects you do:

1. put it into a GTK container (the count is now 2)
2. Unref (the count is 1 and the container holds the object)

for widgets

1. put into a container (the count is still 1, but the widget is no more
"floating," it is owned)
2. do nothing

It is very easy to mess with this. I guess that this is what caused leaking
in the example you are talking about.

> The memory leaks are concerning; it doesn't look to me as if there is a
> solution at the Ada level, and the point of the exercise is to escape
> from C, if possible. If I need to get the full set of GTK sources, build
> them and debug, I might, but it'll take a lot longer...

Sources are available at:

http://www.gtk.org/

You have to take somewhat outdated ones, because GtkAda lags behind.

For debugging reference counts you can use the Ref_Count function from:

http://www.dmitry-kazakov.de/ada/gtkada_contributions.htm#10.2

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



  reply	other threads:[~2007-09-16 14:53 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-09-16 14:11 Ada newbie + Gtkada + Win2000 = ? Brian Drummond
2007-09-16 14:53 ` Dmitry A. Kazakov [this message]
2007-09-16 23:54   ` Brian Drummond
2007-09-16 18:12 ` michael bode
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox