Hi,
If I have a TParticle Type that I create an instance of, and I also have an instance of a TTracker type that has a TParticle field which I point to the instance of the TParticle, then I add the instance of the TTracker Type to a list (still with me?) then later on I do List.Remove(t) where t is my TTracker type instance, will the field within it which points to the TParticle type be freed so that the TParticle will now be freed by the garbage collection properly? I hope so. Trying to think how I can diagram this in text. Anyway here's some example code (tested it compiles):
I know I could code this a different way, but I need it this way for a specific purpose and I just want to check that the memory will be freed up properly. Any ideas?
Thanks.
If I have a TParticle Type that I create an instance of, and I also have an instance of a TTracker type that has a TParticle field which I point to the instance of the TParticle, then I add the instance of the TTracker Type to a list (still with me?) then later on I do List.Remove(t) where t is my TTracker type instance, will the field within it which points to the TParticle type be freed so that the TParticle will now be freed by the garbage collection properly? I hope so. Trying to think how I can diagram this in text. Anyway here's some example code (tested it compiles):
Type TParticle End Type Type TTracker Field p:TParticle End Type Type TTrackerList extends TList Method AddNew:TTracker(p:TParticle) Local t:TTracker = new TTracker t.p = p AddLast(t) return TTracker End Method End Type Global trackerlist: TTrackerList = new TTrackerList Add() Remove() Function Add() local p:TParticle = new TParticle trackerlist.addnew(p) End Function Function Remove() For t:TTracker = eachin trackerlist trackerlist.remove(t) Next End Function
I know I could code this a different way, but I need it this way for a specific purpose and I just want to check that the memory will be freed up properly. Any ideas?
Thanks.