lua-users home
lua-l archive

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



Oh, interesting. I didn't realize that weak tables removed their *entry*.
This is not the weak reference I learned as a youngster  :)

Thanks!

-Erik



> -----Original Message-----
> From: lua-bounces@bazar2.conectiva.com.br [mailto:lua-
> bounces@bazar2.conectiva.com.br] On Behalf Of Matt Campbell
> Sent: Monday, January 08, 2007 1:32 PM
> To: Lua list
> Subject: Re: userdata as table keys
> 
> Erik Cassel wrote:
> > Don't forget to remove the key-value pair after the COM object is
> gone... or
> > you'll start to leak registry memory.  Does your usedata's destructor
> clean
> > up its own registry entry?
> 
> That's not necessary.  As I attempted to explain earlier, the userdata
> references aren't stored directly in the registry, but in a table
> referenced by the registry.  The table which references the userdata has
> a metatable, and that metatable's __mode value is "v", so the values are
> weak references; the garbage collector will do the necessary cleanup
> itself; my __gc metamethod only has to release the wrapped COM object.
> See the Weak Tables chapter in _Programming in Lua_ (http://lua.org/pil/).
> 
> I hope this helps.
> --
> Matt Campbell
> Lead Programmer
> Serotek Corporation
> www.freedombox.info
> "The Accessibility Anywhere People"