On Nov 12, 2006, at 10:47 PM, Brendon Costa wrote:
I think i am having trouble with the garbage collector deleting
the memory for tree nodes that i am still using.
You must have a reference to that data from gc managed memory. If
you don't use use gc to allocate the data structures, it just won't
work. In addition, the roots of all such data structures have to be
findable from the gc roots. The compiler is littered with examples
of how to do this, as an example:
static GTY(()) tree block_clear_fn;
is findable by the gc system. All data findable from this tree, will
be findable by the GC system.
If you _must_ have references outside gc, you can do this, if there
is at least 1 reference within the gc system. For example, if you do:
static GTY(()) tree my_refereces;
void note_reference(tree decl) {
my_references = tree_cons (NULL_TREE, decl, my_references);
}
and call note_reference (decl) for every single bit you save a
reference to, it'll work. Actually, no, it won't work, precompiled
headers will fail to work because you'd need to modify the PCH writer
to write your data, because you didn't mark your data structures with
GTY and didn't use gc to allocate them. See the preprocessor for an
example of code that doesn't use GTY and yet writes the data out for
PCH files.