lua-users home
lua-l archive

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


Hi,

I have a small question on the way the garbage collector is recovering
useless variables.

I have some application like that

function  xxx ()
  local handler1 =  function_that_return_userdata()

  some processing  ...

  and later in the code

  local handler2 = another_function_that_return_userdata()

  some processing ...

end

I installed a metatable on the userdata for __gc to close to end
the processing, close files... but handler2 needs to be destroyed before
handler1

if handler1 is destroyed before handler2 the call to end the
processing will fail and some memory will be lost and some files will
stay opened...

is there a way to predict how the garbage collector will collect the
variable or do I  need to add some code to keep track of the opened
handler2 ?

Thanks for your help,

--
Didier Derny
didier@derny.org