We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › delete instance of class
Page Index Toggle Pages: 1
delete instance of class? (Read 326 times)
delete instance of class?
Oct 28th, 2008, 4:49am
 
Hy,

i have a program that use multiple classes, and i would like to create and kill the instances in run time, something like:

Code:

if (key == 'a'){
myClass = new Class();
}

if (key == 'b'){
kill myClass
}


it is possible?

thanks in advance.
Re: delete instance of class?
Reply #1 - Oct 28th, 2008, 12:31pm
 
You can't explicitly delete an instance of a class, you just stop referring to it, and it'll get cleaned up.

e.g.
myObj=new Fooclass();
...
myObj=null; // now we don't refer to it, it'll get deleted.

or even:
myObj=new Fooclass(0);
...
myObj=new Fooclass(1); // the Fooclass(0) instance is now not refered to and will get deleted.
Re: delete instance of class?
Reply #2 - Oct 28th, 2008, 7:36pm
 
thanks JohnG!
Page Index Toggle Pages: 1