Guarantee Delete()?

BlitzMax Forums/BlitzMax Beginners Area/Guarantee Delete()?

SculptureOfSoul(Posted 2006) [#1]
Is there an easy way to guarantee Delete() will be called for a global object at the end of the program?

I've got a global object that logs some stuff upon it's deletion. Sometimes it might be deleted before the program ends, although it will usually last the life of the program.

Judging from the logs, it seems Delete() is never called.

I tried doing: OnEnd GCCollect

but that didn't work either. My guess was that was because the object hadn't been nullified yet. Nullifying the object and then calling GCCollect did work...but it's a clunky workaround. I have to specifically write a function that nulls out all of the global objects and then calls GCCollect - and then feed that function to OnEnd.

Is there any way to guarantee Delete() is called when the object goes out of scope (and it's a global object)?


Perturbatio(Posted 2006) [#2]
http://www.blitzbasic.com/Community/posts.php?topic=53545

you could create a global array which stores your other globals, then just do a foreach through them, nulling them along the way.


H&K(Posted 2006) [#3]
guarantee Delete() will be called for a global object at the end of the program?


NO. Make it Free() and call it yourself.


SculptureOfSoul(Posted 2006) [#4]
Well, I would, but the idea was that the log would note additional information in situations where the program ended unexpectedly.


H&K(Posted 2006) [#5]
well, if the program ended unexpectedly, ie Crashed why would you expect the GC to not crash?