Re: Memory Leaks



On Tuesday 23 August 2005 19:57, Andrew Krause wrote:
> I think this is more of a general C/C++ question, but I'll try
> here. My problem is that as my application runs longer, the memory
> usage slowly creeps up higher and higher. For example, if I call
> my Environment Settings dialog five times in a row, each time it
> uses more memory.
>
> Now this makes sense except that I am hiding the dialog and then
> using g_free() to free the memory that was allocated by the dialog
> after each hide. It sort of becomes a problem after a while
> because too much memory is being used, although this threshold
> usually doesn't appear for a few hours.
>
> I know I am probably just being ignorant, but I've never programmed
> any application that was large enough that I had to worry about
> memory allocation at all. Thanks for any help you can give me!

You don't say how you are measuring memory usage and your measurements may not 
be accurate.  However, you don't free GTK+ dialogs with g_free() as it uses 
reference counting for memory management.  You should normally use 
gtk_object_destroy() on the top level window.

See http://developer.gnome.org/doc/API/2.0/gtk/GtkObject.html for an 
explanation of memory management for GTK+.

Chris



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