lua-users home
lua-l archive

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


On 30/04/2011 18.41, Mark Hamburg wrote:
On Apr 30, 2011, at 1:20 AM, Henk Boom wrote:

On 29 April 2011 19:09, uki<ukaszg@gmail.com>  wrote:
local _M = {}
-- stolen from: https://github.com/kikito/middleclass/wiki/Private-stuff
local _private = setmetatable({}, {__mode = "k"})

--constructor
function _M:new(...)
   local object = {}
    -- do stuff

   _private[object].privateField = 1
   return object
end

Just beware of memory leaks pre-5.2 if the value contains a reference
to the object.

That applies to indirect references as well. If you want to always go through a proxy object, you are probably better off using a userdata and using its environment to point to the Lua table.


Sorry, I really miss something here. I don't understand what memory leak you and Henk are talking about.

Would you like please giving some hints/pointers on the subject, thanks

Mark





--
Lorenzo