Re: RecentManager, singleton



On Thu, 2008-03-20 at 19:05 -0300, Jonh Wendell wrote:
> Hi, folks.
> 
> In GtkRecentManager we have a singleton, by using _get_default() API.
> 
> My doubt is: When is the static singleton object freed? The
> documentation says to not ref or unref it, and that it will be destroyed
> when application terminates.

yes.

> Looking through its source code (gtkrecentmanager.c), I haven't found
> where it is unref'd.

the RecentManager singleton is synchronised when the depth of the main
loop reaches 0 (which is usually when an application quits); the state
of the recent files list is, thus, always consistent.

the memory is reclaimed by the operating system, along with the rest of
the data that is a one-shot creation of the glib, pango and gtk+
libraries; if you look at the valgrind output, you'll notice it - but
it's easily filtered using the appropriate "skin": as I said, the memory
is effectively reclaimed by the OS.

if you want to personally manage the memory and lifetime of a
RecentManager instance you can create one using gtk_recent_manager_new()
and then use g_object_unref() when needed.
gtk_recent_manager_get_default() is there so that you don't need to do
the bookkeeping yourself, and so that you are guaranteed to have the
same instance throughout your application.

ciao,
 Emmanuele.

-- 
Emmanuele Bassi,
W: http://www.emmanuelebassi.net
B: http://log.emmanuelebassi.net



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