The only entity that matters in your example is anExistingInstance
. We don't know where it's defined and who holds the reference to it, but this object holds a reference to the SomeClass
instance. It doesn't matter who created the SomeClass
instance, just that anExistingInstance
holds a reference to it. Some other class probably holds a reference to anExistingInstane
, and so forth down the chain until you reach a GC root.
As long as your instance of SomeClass
is linked back to a GC root, it won't be garbage collected. Once any link in this chain is no longer linked to a GC root (let's say, someone released the reference to anExistingInstance
, all the objects referenced by it (which aren't referenced by something else) are eligible for garbage collection.