Problem with Release

BlitzMax Forums/BlitzMax Beginners Area/Problem with Release

SSS(Posted 2005) [#1]
hi all.. i've a problem with the new way of deleting objects in v. 1.3... i know i should just let the object fall out of scope but here's my problem, when i used to call release it would likewize call the delete function of an object, however just setting a pointer to an object to be null does not call the delete function. And considering the object is pointed to by several other objects that only that object knows about i cant delete objects in anywhere near an elegant manner using this new system. How do you guys do it?


Shambler(Posted 2005) [#2]
I would assume that FlushMem will only delete the object when the reference count to that object is zero.

Maybe you could consider changing your code so that you do not have other objects pointing to this object?

[edit] one possible way to do what you want would be to have a global variable e.g.

gObjectDelete%=the handle of the object you are deleting

In your update functions for the other objects, check this global variable and if any of the other objects are pointing to it then make them release and null their pointers to it.

Once you have iterated through all the other objects then null the object itself and then call FlushMem.


rdodson41(Posted 2005) [#3]
I've been experimenting with creating some simple data structures, and once I tried making a linked list structure similar to the one that came with BMX. Basically, every item in the linked list has two variable references to 2 other items. I have a main type, List, and the items are of a type, Link.

Say my instance of List has a variable reference of the first Link in the list which is the first in the chain of links. Now these other links are not referenced in any other way besides the two in each link referencing the previous and next links. Only the first link is connected to the rest of my program by one variable in my instance of List. Say I nullify this one variable in List, and so these links are now just floating in space. They are connected to eachother, but not to the rest of the program. Since I cant access these any more because I deleted the reference to the first one, will they all automatically get deleted, or since they are still interconnected but not referenced by any other variable they will still be there?


FlameDuck(Posted 2005) [#4]
Since I cant access these any more because I deleted the reference to the first one, will they all automatically get deleted, or since they are still interconnected but not referenced by any other variable they will still be there?
It would still be there. The main difference between the automatic garbage collector in BlitzMAX and the garbarge collector in Java or the .Net CLR is that the BlitzMAX garbage collector does not count root objects. Only references. Thus any cyclic, orphaned data structures will not get released.


rdodson41(Posted 2005) [#5]
Thats too bad. I wanted to just nullify the references to the head and be done with it, but I guess it's not that easy.