[prev in list] [next in list] [prev in thread] [next in thread]
List: lua-l
Subject: Re: Garbage collecting in general
From: Edgar Toernig <froese () gmx ! de>
Date: 2001-02-22 16:19:06
Message-ID: 3A953BFA.72EF4C6D () gmx ! de
[Download RAW message or body]
Hi,
Falko Poiker wrote:
>
> I have a lua userdata type called "selection" that is a mirror of a
> selection class we have in our game. This lua type has a garbage collection
> tag method defined for it that deletes a selection instance in the game (the
> one being pointed to by the userdata object).
>[...]
> Why is garbage collection not working for me? Am I doing something
> fundamentally wrong here?
Some things you should check: First, are you using the correct tag in all
places? Does the userdata get the right one? Is the gc-method set for
the same? Then, are you sure you do not create additional references to
your selection userdata? Example:
function foo()
local x = make_selection(...) -- returns the userdata
y = x
...
end
Here after executing foo you still have a reference to your selection
in the global y. And as long as this reference exists your gc-method
will not be called! An y=nil/0/""/... is required to remove this ref-
erence. It's not like in some languages that the destruction of x calls
the destructor (the gc-method). Destroying the last reference to an
object calls it. And last, did you create references within the C
program via lua_ref(L, 1)? Make sure that _each_ lua_ref call has the
appropriate lua_unref (and this can't be in the gc-method!).
Ciao, ET.
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic