Re: Gtklist and memory leakage



Ian King wrote:
> The same thing also happens with buttons in boxes, in fact anything with
> gtk_container_add I guess is doing this.  The way it is at the moment if I
> keep adding and removing eventually I will run out of memory, which is of
> course bad.  Is this correct?

Hi Ian, I tried this test program: create and destroy a 50 item list lots of
times.

It runs in constant space for me (at least as reported by "top"). Memuse creeps
up a little at the beginning, but stabilises at around loop 7000 and doesn't
grow again (I waited for loop 15,000). This was with gtk+-1.2.10.

Don't know if this helps to narrow it down at all :-(

John
-- 
#include <stdio.h>
#include <stdarg.h>
#include <assert.h>

#include <gtk/gtk.h>

typedef struct {
        GtkWidget *window;
        GtkWidget *list;
} Contents;

static gint
timeout_cb( Contents *contents )
{
        static int n = 0;
        char buf[256];
        int i;

        gtk_list_clear_items( GTK_LIST( contents->list ), 0, -1 );

        snprintf( buf, 256, "Loop %d", n++ );

        for( i = 0; i < 50; i++ ) {
                GtkWidget *item;

                item = gtk_list_item_new_with_label( buf );
                gtk_container_add( GTK_CONTAINER( contents->list ), item );
                gtk_widget_show( item );
        }

        return( TRUE );
}

int
main( int argc, char **argv )
{
        Contents contents;

        gtk_set_locale();
        gtk_init( &argc, &argv );

        contents.window = gtk_window_new( GTK_WINDOW_TOPLEVEL );
        contents.list = gtk_list_new();
        gtk_container_add( GTK_CONTAINER( contents.window ), contents.list );
        gtk_widget_show_all( contents.window );

        gtk_timeout_add( 100, (GtkFunction) timeout_cb, &contents );

        gtk_main();

        return( 0 );
}
-- 

> 
> Ian King
> 
> -----Original Message-----
> From: gtk-list-admin gnome org [mailto:gtk-list-admin gnome org]On
> Behalf Of Sven Neumann
> Sent: Friday, August 03, 2001 5:06 PM
> To: Ian King
> Cc: GTKLIST
> Subject: Re: Gtklist and memory leakage
> 
> Hi,
> 
> "Ian King" <king eiffel com> writes:
> 
> > Does anyone know of any memory leakage problems with gtklist?  Is seems
> that
> > if I add, say 50 list items to a list (individually with
> gtk_container_add),
> > clear the list, add another 50, the memory is never reclaimed.  Does
> anyone
> > else have this problem, is there a way to resolve it?
> 
> GtkList uses a GList to store its data and GList uses a GMemChunk created
> using G_ALLOC_ONLY with a number of pre_allocated elements of 128. This
> means, GList elements are allocated in bunches of 128 and are never freed
> but stay around for later reuse. To change this, you can push a different
> GList allocator using g_list_push_allocator().
> 
> Salut, Sven
>




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