Re: Run Loop Memory Management



On Tue, 29 May 2007 18:12:57 -0500 Dan Saul wrote:

Good day, new to the list and GTK+ in general.

I am formerly a Macintosh developer. Currently however I am now working
on Objective C bindings for GTK+. I am currently looking at the
documentation for the run loop which I have found located at
http://developer.gnome.org/doc/GGAD/sec-mainloop.html . 

My question is, I need to implement the autorelease pool's run loop
hook that basically runs once every run loop cycle and frees memory.
So far guint gtk_idle_add(GtkFunction function, gpointer data); looks
the most promising for this purpose. However, being new to this
library I would like to get the opinions of those who are more
experianced whether there is a better -- or more appropriate place for
me to put this code.

You're correct, sorta.  For starters, please don't use that reference
for new gtk2-based code.  That book (while excellent) is old and refers
to gtk 1.2, which hasn't been maintained for many years.

In gtk 2, gtk_idle_add() has been replaced by g_idle_add().  You can
look at the glib reference documentation here:
http://developer.gnome.org/doc/API/2.0/glib/

I'm not entirely certain that a function added using g_idle_add() will
actually run with every main loop cycle.  It may only run when there's
a certain level of inactivity, and you might want to use
g_idle_add_full() to raise the priority higher.

However, are you sure this is the best way to do this?  Using an idle
function will chew through CPU cycles while the application is
otherwise idle (really hurts laptop battery performance, for one
thing).  Another option is a timeout using g_timeout_add(), but the
correct approach would be to add a custom GSource that is only invoked
when it needs to be.

Actually, you might want to poke around in gdk/quartz/ inside gtk+
SVN.  I imagine autorelease pools are used in the MacOSX backend; maybe
you can find some hints there as to what's best.

        -brian



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]