Re: Memory Management



Meghal Harish Varia <varia ecf utoronto ca> writes:
> 
> I was wondering how memory management works in gtk+.  I've seen many
> examples where allocation is performed using gtk_object_new(), but never
> destroyed.  Does gtk+ maintain a list of all allocated objects and
> automatically destroy them when the application is destroyed?
>

Nope. However frequently you pass the object to some owner that will
destroy it, for example child widgets are destroyed by their
container.  Object life cycle is explained in almost all the GTK/GNOME
books out there.

> Are there any exceptions to this (that would require the programmer to
> destroy objects).  For example, I know that when using glib's string
> functions, you have to deallocate the memory returned yourself.
> 

There are plenty of exceptions; e.g. for the string functions about
half of them don't in fact return allocated memory, you shouldn't free
it at all.

Ain't C/C++ fun!

You need to check the reference docs (or worst case the source code)
for any functions you have questions about.

Havoc





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