I’ve got 2 lists, where both hold objects of same type. Let’s call it TypeX.
When I want to add a new object of TypeX I’d create a new object of TypeX and then use Add to list1 and to list2. Thus each list will have a reference to the actual object.
(I hope I’m right here).
Then, I’d want to remove the object. I’d use Remove for both lists. Thus the reference to the object has been removed…
But what happens to the object itself? Will the GC clean it? Should I remove it somehow else?
In simple terms, the GC collects every object that is not referenced by any other object.
So, if you remove your object from both lists and don’t save it anywhere else it will eventually be garbage collected.