[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
On garbage collection...
- To: info-macl@cambridge.apple.com
- Subject: On garbage collection...
- From: Luke Hohmann <hohmann@csmil.umich.edu>
- Date: Mon, 10 Aug 92 07:20:46 -0400
(Please excuse the simplicity of this question - I do not know very much
about garbage collection algorithms....)
In my application, I have instances of objects organized in an hierarchical
structure, with forward and backward pointers (slots) set to the appropriate
variables. For example, consider the following structure, in which children is
a slot that contains a list of children, and parent is a pointer to the
single parent of the node.
+------+
|root | +----------+ +----------+
| children--+------->|node1 | |node3 |
+------+ | | children------>| children|
^---------|-----------parent |<--------parent |
| | +----------+ +----------+
| |
| | +----------+
| +------->|node2 |
| | children|
+---------------------parent |
+----------+
My question is, if I remove node1 from the structure above by setting the
children slot of root to be '(node2) and setting the parent slot of node1
to nil, (resulting in the following structure), will node1 and node3 be
garbage collected?
+------+
|root | +----------+ +----------+
| children--+ |node1 | |node3 |
+------+ | | children------>| children|
^ | | parent |<--------parent |
| | +----------+ +----------+
| |
| | +----------+
| +------->|node2 |
| | children|
+---------------------parent |
+----------+
Or, must I explicitly set the children of node1 and the parent of node3 to
nil before node1 and node3 will be garbage collected?
To take the "safe" route, I intend to rewrite my code to ensure that the
children of all deleted nodes have nil for all slot values, but I was
just interested in the general question.
Thanks for your time.