Destroying class instances?

Is there a way to destroy an instance of an object? I've been looking through the documentations but don't see anything to destroy/disable the instance as a whole.

I’m not totally sure, but I’d think that myObject = nil would be sufficient.

from what i've seen that only works outside of the instance unfortunately, for what i'm doing i'd need to call it from within a function of the instance itself :slightly_frowning_face:

I can only think of a roundabout solution, e.g. from within the object, add it to a “objectsToRemove” table. Then in your update, check if there are any members of that table and remove them :slightly_smiling_face:

1 Like

Yeah, agree with @neven . Objects don't destroy themselves. They might set a boolean to mark themselves as being candidates for removal.

To elaborate: there's no need to manually delete or destroy objects in Lua; they're reclaimed by the garbage collector once there are no more references to them in scope. If you find this isn't happening frequently enough or at the right times, you can control it somewhat. See
Garbage collection in the docs.

1 Like

oh yeah, i think the issue is that i call the instance's draw function within main's update function. I just couldn't figure out how to circumvent that i suppose