I am currently trying to do OOP in Lua. From what I've understood here, the instance of a class and even the class ( the variable ) itself are a reference to the various bits and bobs the class holds, so if I have a method :destroy(), consisting of
function class:destroy()
self = nil
end
when I call instance:destroy()
the reference instance should be picked up by the garbage collector and practically, the instance as in an object is gone.
It won't throw up an error or slowly cause a memory leak, right?
EDIT : I thought that maybe I should include the following as well.
This is the method I use to create and instance
function class:new(obj)
obj = obj or {}
setmetatable(o,self)
self.__index = self
return o
end