Bug? glib. boehm-gc integration



Hi Friends,

	I've been trying to register a garbage collector with glib with
only some good results. First, I HAVE set ENABLE_GC_FRIENDLY to 1 in
config.h as well as run "configure --enable-gc-friendly" (and of
cource recompiled). I have also tried to disable the memory pooling with
the appropriate flags, to no avail.

	First: what works. g_new correctly allocates and frees memory. The
sample program below keeps the memory bounded to a few k as it should.

/*
PROGRAM #1 
	MEMORY COLLECTION WORKS GOOD
*/

#include <gc.h>
#include <glib/glib.h>
#include <string.h>
#include <stdio.h>

char *mstrdup(char *s){
  char *ns = g_new(char,strlen(s)+1);
  strcpy(ns, s);
  return ns;
}

int main(void){
  int i,j;
  GMemVTable mem;

  memset(&mem, 0, sizeof(GMemVTable));
  mem.malloc  = GC_malloc;
  mem.realloc = GC_realloc;
  mem.free    = GC_free;
  g_mem_set_vtable(&mem);



 THIS_LOOP_WORKS:
  while(1){
    char *s;
    double *d;
    int *i;
    s  = mstrdup("this that and the other");
    d  = g_new(double,1);
    *d = 4.56;
    i  = g_new(int,1);
    *i = 234;
  }
}
/*
END PROGRAM #1
*/

	Second: what does not work. It seems that the liberary containers
are not working correctly. The following program does not keep the memory
bounded.

/*
PROGRAM #2
*/
#include <gc.h>
#include <glib/glib.h>
#include <string.h>
#include <stdio.h>

char *mstrdup(char *s){
  char *ns = g_new(char,strlen(s)+1);
  strcpy(ns, s);
  return ns;
}

int main(void){
  int i,j;
  GMemVTable mem;

  memset(&mem, 0, sizeof(GMemVTable));
  mem.malloc  = GC_malloc;
  mem.realloc = GC_realloc;
  mem.free    = GC_free;
  g_mem_set_vtable(&mem);


 THIS_LOOP_DOES_NOT_COLLECT_MEMORY:
  while(1){
    GTree *tree;
    tree = g_tree_new((GCompareFunc) strcmp);
    g_tree_insert(tree, mstrdup("this"), NULL);
    g_tree_insert(tree, mstrdup("that"), NULL);
    g_tree_insert(tree, mstrdup("and the"), NULL);
    g_tree_insert(tree, mstrdup("other"), NULL);

    /* Do not free tree. Should be garbage collected!*/
  }
}
/*
 END PROGRAM #2
*/
	I've seen similar results for an endless allocating
GArray's. Initially I thought that the problem was with the memory chunk
sub-system, but I've compiled the code with memory chunks off and I get
the same problem.

	The way that I monitor the memory usage is by using "top" on
a mandrake 7.0 machine. I'm using boehm-gc: 6.1 and I'm using
glib-2.0.7. Thanks for any help


Pete





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