How do I release an object?

BlitzMax Forums/BlitzMax Programming/How do I release an object?

JoshK(Posted 2006) [#1]
What is the correct way to do this?:
bank:tbank=createbank()
release bank



GW(Posted 2006) [#2]
bank = Null


CS_TBL(Posted 2006) [#3]
bank=null

And I prefer to GCCollect() regulary, but esp. after null'ing things..

I'm still not sure whether I like all this high-level memory-management.. but alas..


N(Posted 2006) [#4]
Release is a command used only to release integer handles of objects. If you're using Strict (and you should be, otherwise you're going to end up shooting yourself in the foot), it's useless.

The correct means of doing this is bank = Null, and if you want to force the immediate collection of the object, you call GCCollect( ) (this is called automatically by BlitzMax during runtime, and since it's better to perform this stuff in batches, you're likely to be better off letting BlitzMax handle the management of object memory).

However, this rule does not apply to memory allocated with MemAlloc, MemExtend, etc. as that is outside the scope of the garbage collector. Banks are basically managed wrappers of MemAlloc, so it's probably better to just stick with them. However, it is worth mentioning.

Edit: Some folks beat me to it, albeit with less helpful answers.


gman(Posted 2006) [#5]
Release goes hand-in-hand with HandleFromObject. HandleFromObject increases the internal reference counter and returns an integer handle to an object. you can use this integer handle with HandleToObject to convert it back into an object. unlike HandleFromObject, HandleToObject does _not_ affect the reference counter. if all object references to the object are set to null the object will still not be garbage collected until Release is called on the integer handle. this works at all strict levels.
SuperStrict
Framework BRL.Blitz

Type test
	Field i:Int=15
EndType

Local temp:test=New test ' reference count is 1
Local hTemp:Int=HandleFromObject(temp) ' reference count is now 2

temp=Null ' reference count is still 1
DebugLog(test(HandleToObject(hTemp)).i)
Release(hTemp) ' references are now 0



boomboommax(Posted 2006) [#6]
you should probally read the docs...


maximo(Posted 2006) [#7]
you just open your hand and drop it, simple as that..