Let's say I've got an object:
var o1 = {
someKey: 'value'
};
and another object that references that first object:
var o2 = {
o1Ref: o1
};
and also a third object that references a property on the first object:
var o3 = {
o1propRef: o1.someKey
};
Then, let's say o2
is garbage collected. Does the reference to o1.someKey
on o3
prevent o1
from being collected?
Then, also, suppose o1
is bigger, say:
var o1 = {
someKey: 'value',
someBigValue: Buffer(2000000)
};
Can the parts of o1
that aren't being referenced be collected, or are objects collected as a whole? It seems like, with the second version of o1
, o3
is just holding on to o1.someKey
and o1.someBigValue
can be freed up.
Also, I do realize this might vary among implementations. If that's the case, whats' the best way to think about this generally?