Suppose I have a two-way linked list. I want to remove a sequence from it like this:
begin - element - element x element - element - element x element - end
\_________________________________/
-: reference
x: removed reference
I would like to know if I also should remove the references between the elements that are to be removed, or if the garbage collector handles it in a better way.
the standard garbage collector uses a mark and sweep algorithm which can handle circular references so there is no need to null those (only the references from reachable memory to unreachable should be nulled)
You do not need to remove those references. The garbage collector can trivially determine that the three elements that you are removing are no longer reachable, so there is no need to scan them for possible pointers. In other words, there is no performance gain in doing so.
To see why this is the case, consider the first algorithm presented in this blog post: http://xtzgzorex.wordpress.com/2012/10/11/demystifying-garbage-collectors/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With