T
Tegiri Nenashi
I'm not sure I ever saw a convincing example. Let's consider the two
frequented in the literature.
1. HashMap (why not other collection?). I understand that if a
reference to HashMap is still reachable, the whole HashMap and their
references would be reachable, if the reference to HashMap is gone,
the referred objects (keys and values) would decrement their counts
(although counts don't really matter in mark-and-sweep method) . If a
key and a value is not reference anywhere else, then key is supposed
to be marked as garbaged collected. Finally, with the key holding no
references, it is value that is marked to be garbage collected as
well.
2. Listeners. Let's assume a button widget declares a click listener.
So we have a circular reference, and both objects would be garbage
collected when no longer referenced without a problem.
The problem I can imagine is crossing programming environment
boundaries with native calls, but I fail to see this idea supported
anywhere in the literature.
Am I missing something obvious? (Except the idea of a reference that
not guaranteed to be valid at any time being a very insult to common
sense in programming?)
frequented in the literature.
1. HashMap (why not other collection?). I understand that if a
reference to HashMap is still reachable, the whole HashMap and their
references would be reachable, if the reference to HashMap is gone,
the referred objects (keys and values) would decrement their counts
(although counts don't really matter in mark-and-sweep method) . If a
key and a value is not reference anywhere else, then key is supposed
to be marked as garbaged collected. Finally, with the key holding no
references, it is value that is marked to be garbage collected as
well.
2. Listeners. Let's assume a button widget declares a click listener.
So we have a circular reference, and both objects would be garbage
collected when no longer referenced without a problem.
The problem I can imagine is crossing programming environment
boundaries with native calls, but I fail to see this idea supported
anywhere in the literature.
Am I missing something obvious? (Except the idea of a reference that
not guaranteed to be valid at any time being a very insult to common
sense in programming?)