Given the following answer to a related question (https://stackoverflow.com/a/22086392/1420752) are objects reference counted in Windows-targeted Delphi applications?
I.e.:
Q1A does the following object have a reference count of 2 after the second statement?
o1 := TMyObject.Create;
o2 := o1;
Q1B Following on from the above, will assigning o1
to nil
drop the reference count to 1?
o1 := nil;
Q1C Again following on, will assigning o2
to nil
drop the reference count to 0?
o2 := nil;
Q1D Moving forward, if the above is correct and the object now has a reference count of 0, I understand that the compiler will NOT automatically free the object (o2.Free
should have been called prior to o2 := nil
above in order to prevent a memory leak). Remember I'm talking about a Windows target, not a mobile target with automatic reference counting (ARC).
Q1E If reference counting does not automatically free the memory associated with an object, then what precisely is the point of reference counting in Delphi (e.g., is it to help trace memory leaks)?