glist doesn't free mem
- From: "Aldrin Martoq A." <agm cec uchile cl>
- To: gnome-devel-list gnome org@cipres.cec.uchile.cl
- Subject: glist doesn't free mem
- Date: Thu, 2 Dec 1999 03:15:43 -0300 (CDT)
Hello, I was wonder why my test app consumes more and more memory... So I
make a little test and found that glist doesn't free !!!
-----1.c-------
#include <glib.h>
typedef struct
{ guint ano;
guint sem;
gchar *dep;
GList *cur;
gchar *coment;
} CatCatalog;
main(int argc, char **argv)
{ int i,j;
int imax = atoi(argv[1]);
GList *l = NULL;
g_print("enter empieza");
getchar();
for (j=1; j<=2; j++)
{ l = NULL;
g_print("alocando %i elementos ...", imax*j);
for (i=0; i<(imax*j); i++)
{ CatCatalog *c = (CatCatalog *) malloc(sizeof(CatCatalog));
l = g_list_append(l, c);
}
g_print(" ya");
getchar();
g_print("liberando %i elementos ...", imax*j);
for (i=0; i<(imax*j); i++)
{ CatCatalog *c;
c = (CatCatalog *) g_list_nth_data(l, i);
free(c);
}
g_print(" ya");
g_list_free(l);
getchar();
}
}
----eof---
compile with "gcc 1.c -o 1 `glib-config --cflags --libs glib`". Then:
% ./1 10000
enter empieza # top says 396K
alocando 10000 elementos ... ya # top says 784K
liberando 10000 elementos ... ya # top says 784K !!!!!
alocando 20000 elementos ... ya # top says 1140K
liberando 20000 elementos ... ya # top says 1140K !!!!!
I don't understand why if I free'd everything, its still there. If I use
an array instead of GList*, top says what I expect...
What am I doing wrong?
Aldrin. "Caution! Under no circumstances confuse the mesh with the
Area de Ingenieria interleave operator, except under confusing circumstances!"
CEC U.Chile The INTERCAL Programming Language Revised Reference Manual
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]