lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


I write a simple OO program in lua. But I don't understand, why the objects keeps in memory after destruction...

[0:~/prg/lua]$ lua oo.lua 
Side name is: Hello

Side name is: World

105     202
104     208
lua: oo.lua:38: attempt to index local `moo' (a nil value)
stack traceback:
        oo.lua:38: in main chunk
        [C]: ?


== That's the code:


Square=
{
  side=nil,
  posx=0,
  poy=0,
  created={}
}
function Square:new(side)
    local new_inst={}
    --setmetatable(new_inst,mt)
    setmetatable(new_inst,{__index=Square});
    new_inst.side=side;
    return new_inst;
    --table.insert(Square.created,self);
    --return self;
end

function Square:show()
    moo=self.side
    print ("Side name is: "..moo.."\n");
end

function Square:delete()
    self=nil
    collectgarbage()
    return self
end


local moo=Square:new("Hello");
local boo=Square:new("World");
moo:show();
boo:show();

print (gcinfo());
moo=moo:delete();
print (gcinfo());
moo:show();