How do you kill an instance?

I have finally got my head around using classes to pass data to different method (really cool) and I am creating a new instance of a class for each row in a table as I loop through it but I was wondering if I should kill the instance after I have finished doing what I need and before I create a new one. If so how do I kill of the instance?

myInstance = nil should work well, although it’s not necessary, since Xojo handles all that stuff for you.

Classes “die” when then go out of scope… or a new instance of the SAME variable is created.

x=new myclass
..... so stuff
x=new myclass ' first version of "myclass" is gone, and replaced with a new one

or set to nil.

You kill an instance by dropping the reference to it.

Explicitly:

dim c as class1
c = new class1
...
c = nil

Implicitly:

dim c as class1
c = new class1
...
c = new class1     // the original object is destroyed

Edit: what they said.

Ah that makes sense, I thought I had to do the housekeeping, good old Xojo :wink: Thanks

The only time you have to do something special is if there’s a cyclic link involved, which can also be formed by delegates/AddHandler.

Ok Will, I was impressed that I have got my head around basic oops, now looking at what you have written I am starting to wonder if I will ever fully grasp things :wink:

You will Nathan, and the question you asked is an example of how we’ll you are progressing!

Have a look at weakRef…