How to destroy object(self) from method
BlitzMax Forums/BlitzMax Beginners Area/How to destroy object(self) from method
| ||
I tried the following, which did not work.Method Destroy() self=Null End Method |
| ||
not possible, anything you can set to null is only a reference. |
| ||
If all references to an object are deleted (nullified), it will be removed by the garbage collection. |
| ||
So if I create an object like thisGlobal gamelist:TList=CreateList() Type SomeObject Field x:Int,y:Int Function Create(startx:Int,starty:Int) Local newgameobject:Tplayer=New Tplayer newgameobject.x=startx newgameobject.y=starty ListAddFirst(gamelist,newgameobject) newgameobject=Null 'set this to null End Function End Type SomeObject.Create(320,240) 'object to be deleted For Object:SomeObject=EachIn gamelist ListRemove(list,Object) 'remove the object from list Next Would this completely delete the object? |
| ||
So if I create an object like this Yes. Note also that the newgameobject in the Create function doesn't need to be nulled. It will be invalid once the scope of the function has ended (upon return). [...] Would this completely delete the object? |
| ||
Thanks. |
| ||
Thank you, I have had a similar question for a while now. |
| ||
When you add an object to a list, it returns a TLink which acts as a shortcut to that object. You can use this link to quickly remove an object from a list. You can add the object to the list in the New method so it always happens automatically. |