ItsA shame that I need to ask such basic quastions

Monkey Forums/Monkey Programming/ItsA shame that I need to ask such basic quastions

hardcoal(Posted 2011) [#1]
Since the Reference is soo bad I have to ask so many basic quastions but I
have no choice........

How to delete a Class Object? what is the command or method?


Xaron(Posted 2011) [#2]
First, no need to be ashamed, we all have or had these kind of questions. ;)

Second, you can't delete a class, only instances of a class.

Third, you can't do it in Monkey, the garbage collector does it for you. You can set the instance variable to zero. That will force the garbage collector to clean it up.


hardcoal(Posted 2011) [#3]
sorry, i ment instance, thats why i wrote a class Object.
Thanks Xaron for the quick help
now i have more 93% stuff left to learn :p


therevills(Posted 2011) [#4]
You can set the instance variable to zero


Isnt it null?

' WARNING: BAD EXAMPLE CODE!
if not player.isAlive then
    player = null
end



matty(Posted 2011) [#5]
Also, if you want to be sure something is gone, make sure all references to the object are nulled as well.


ziggy(Posted 2011) [#6]
Class instances are removed from memory when there are no variables pointing to them. That's how high level managed languages usually work.

Local a:= New MyClass 'A is the only instance of this object
Local b:MyClass = a  'Now there ire 2 variables pointing to the same object
a = Null 'The object is not destroyed yet, as "b" is still poiting to it.
b = Null 'The object is now ready to be destroyed automatically by the garbage collector



Samah(Posted 2011) [#7]
therevills: Isnt it null?

Methinks Xaron may be an old-school C coder...

#define NULL 0