[Gc] strange problem: GC needs manually calling to GC_gcollect()?

Zhang Le 69dbb24b2db3daad932c457cccfd6 at gmail.com
Tue Jul 12 13:38:55 PDT 2005


Hi,
  I'm trying using GC (6.5) in a C project, and find some problems.
  My project is a tree search algorithm. GC_MALLOC() is the only GC
function besides GC_INIT() used in my program. I also use a hash table
and linked list which are managed properly with malloc/free.
 
 When running the core routine of my program for many iterations,
which involves lots of GC_MALLOC, my program stops at an assertion
failure:

test_viterbi: viterbi.c:1873: create_node: Assertion `U1 == parent->U' failed.

The corresponding code is:
=== code begin ===
viterbi_tree_node_t* create_node(viterbi_tree_node_t* parent, int state,
    int L, int order) {
    int i;
    viterbi_tree_node_t* node;
    viterbi_tree_node_t* p1 = parent;
    double** U1 = 0;

    if (parent) {
(1)            U1 = parent->U;
    }

  (2)   node = (viterbi_tree_node_t*)GC_MALLOC(sizeof(viterbi_tree_node_t));
    if (parent)  {
 (3)      assert(U1 == parent->U);
        assert(U1);
        assert(parent->U);
    }
...
=== code end ===
at (1), I save the U array of node parent in U1.
then at (2), make a call to GC_MALLOC to allocate a new node
But at (3), I find the parent node's U field changes (to zero), which
is different from the saved pointer  at (1), and cause an assert
failure.

It's quite strange to me. And it seems during the GC_MALLOC call, GC
wrongly clear the memory of the parent node which is allocated by
earlier call to this function and is still in use. Why?

I try to run GC_gcollect(void) every 10 calls to my core routine, and
the problem solves. However, the same problem occurs when I run
GC_gcollect(void) every 30 or more calls to my core routine. My
program uses little memory, and I'm sure I'm not running out of
memory.

Any tips?

Zhang Le



More information about the Gc mailing list