This question is a bit vague I suppose, but I can't really post all the involved source, so vague is as good as it's going to get.
My game objects have a Destroy() method which cleans up after them. I think I do this correctly, but it's always possible I've made a mistake, so I write a little debug note in there to help me spot any circular references.
At the end of my Destroy() method I have this code :
If this is ever greater than one, there is a circular reference I haven't broken. If it's one ( that reference being the one that called this destroy() method in the first place ) then it's clean as a whistle.
My object clears this hurdle, passing back a 1. This sole reference is a local variable, used to cycle through all the objects in a TMap. I've even confirmed 100% for certain that this TMap does not contain the object. As soon as this local variable goes out of scope, the object *must* be ready for collection, right?
Wrong. It never gets collected. I call GCCollect in my main loop ( only for ease of debugging purposes, of course ) and the delete method is never called. This makes no sense to me. I'm confirming the 1 reference, I know what that reference is, and I know that 1 reference can't last, but it's still not being deleted.
The only possible ( logical ) conclusion is that I create another reference after calling the destroy method and before the local variable goes out of scope. The only problem with that theory is that the loop through all the objects in the TMap does nothing else. It simply calls an update method and the call to destroy ( if executed ) is right at the end of the destroy method. Nothing else is executed.
What possible thing have I missed? I can see no logical reason for the object not being collected. Is there a flaw in my logic anywhere?
My game objects have a Destroy() method which cleans up after them. I think I do this correctly, but it's always possible I've made a mistake, so I write a little debug note in there to help me spot any circular references.
At the end of my Destroy() method I have this code :
GCCollect() ' MAKE SURE OBJECTS WE DESTROYED ARE THEMSELVES COLLECTED AND LOSE THEIR REFS DebugLog Byte Ptr(Self)[- 4] + " REFERENCES REMAIN"
If this is ever greater than one, there is a circular reference I haven't broken. If it's one ( that reference being the one that called this destroy() method in the first place ) then it's clean as a whistle.
My object clears this hurdle, passing back a 1. This sole reference is a local variable, used to cycle through all the objects in a TMap. I've even confirmed 100% for certain that this TMap does not contain the object. As soon as this local variable goes out of scope, the object *must* be ready for collection, right?
Wrong. It never gets collected. I call GCCollect in my main loop ( only for ease of debugging purposes, of course ) and the delete method is never called. This makes no sense to me. I'm confirming the 1 reference, I know what that reference is, and I know that 1 reference can't last, but it's still not being deleted.
The only possible ( logical ) conclusion is that I create another reference after calling the destroy method and before the local variable goes out of scope. The only problem with that theory is that the loop through all the objects in the TMap does nothing else. It simply calls an update method and the call to destroy ( if executed ) is right at the end of the destroy method. Nothing else is executed.
What possible thing have I missed? I can see no logical reason for the object not being collected. Is there a flaw in my logic anywhere?