circular reference and Freeing Type

BlitzMax Forums/BlitzMax Programming/circular reference and Freeing Type

Armitage 1982(Posted 2009) [#1]
Hello

I need to clarify some point in BlitzMax please.

I have many Type inside Type.

Some of them are tweener and act like timer so whenever they exist somewhere they will continue to work.

For the moment, when I'm freeing objects, I always implement the Delete() Method in order to automatically (I think) stop/remove and nullify every sub object.

But it feel a bit like nightmare.
I've read that in the next version of BlitzMax the garbage collector will be able to remove Null circular references.

1) Will this be enough to drop implementing Delete() Method ?
2) If I nullify a sub Object with "= Null" is this sub Object will execute his Delete() Method automatically ?

Any Ideas ?

Thanks :)


Jim Teeuwen(Posted 2009) [#2]
Not sure about the first question, but it should be noted that the destructor (Delete method) will only be called when the GC feels like it.

And even then there is no guarantee it will actually be called at all.. If you rely on this when dealing with nested and circular references, it may cause problems because one object may be collected before it should be.


Dreamora(Posted 2009) [#3]
circular references (ie B -> A -> C -> B) are not freed at all unless you are using the multithreaded SVN beta. The regular GC does not detect nor handle those situation. Its a pure ref count based GC and as such a circular reference construct will never reach ref count 0, it will never be freed.

hierarchy objects are freed automatically if their root object is removed.
Even thought delete is not needfully beeing executed, the root will be gone anyway, which results in the child objects to be no longer referenced, which will cause them to be cleaned up as well


Armitage 1982(Posted 2009) [#4]
Thanks Dreamora and Jim T
I hope the multithreaded version of BlitzMax is coming soon this year :)
Although I only need to remove circular references and will probably not using Multithread in this project...

It's really no big deal if the GC don't collect this object as soon as nullifyed, I just want to free correctly my object.