I have a doubly linked list of objects:
class MyObject {
MyObject previousObject;
MyObject nextObject;
// Other fields and methods
}
Only the first object of such a list is directly stored in the application, the other objects are reached through this first object and temporarily used in the application (but no permanent references are kept outside the list itself).
When one does not refer to an object anymore, it is collected by the Garbage Collector.
But, I was wondering whether this is still the case, because the (first) object is still being referenced by the 'next object' in the linked list? And what about the rest of the list, are those objects also collected (even though being referenced by each other)?
Note: I know that I could remove all references in the list when I do not use it anymore. But this is 'hard' due to the nature of the application and results in additional (unnecessary?) overhead.