lua-users home
lua-l archive

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


> > > The Timer() function creates an userdata and stores the callback in a
> > > weak-keyed table. The key is the Timer userdata, and the value is the
> > > callback. The userdata is returned.
> 
> > At this point, unless you store the returned userdata in a variable,
> > there is no strong reference to it.
> 
> Isn't the returned value a strong reference? It is even used to call a member 
> function that creates a strong reference in the registry. Is this really different if I 
> store the result in a local variable? 
> 
> do
>   local t = Timer( function() print"timeout end )
>   t:start(1)
> end

No, it is the same. If you mangaged to put your userdata into
the registry (creating a reference to it), it could not have be
collected. If you are able to retrieve it later from the registry
(accessing that reference), it could not have been collected.

Are you sure only the keys are weak in your table? Are you sure the
callback function has been stored correctly there in the first place?
(You may try to run your code retrieves-the-userdata-from-the-registry-
and-calls-its-callback just after setting everything in place, to see
what happens...)

-- Roberto