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.
How can i determine if it is deleting the memory for this node?
It is safe to assume it is.
I have read the GCC Internals manual on garbage collection, and am
not sure how I should use it in my situation. I have a dynamic array
of my own structs like below:
struct TypeInfoStruct
{
tree node;
.... my data....
};
typedef TypeInfoStruct TypeInfo;
You're missing a GTY(()) marker, see the source code for many
examples, one such would be:
/* Represent an entry in @TTypes for either catch actions
or exception filter actions. */
struct ttypes_filter GTY(())
{
tree t;
int filter;
};
and i have an array of these declared in a .c file:
static TypeInfo** registered_types = NULL;
Again, no GTY marker. Compare with:
static GTY ((length ("typevec_len"))) struct typeinfo *typevec;
I manage the memory for the registered types array and the TypeInfo
structure instances and can not give this to the garbage collector
to do.
If you want this to work, you have to understand the rules to play by,
and play by them, sorry.
struct TypeInfoStruct
{
GTY(()) tree node;
Wrong placement.
.... my data....
};