lua-users home
lua-l archive

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

I am using the luatraverse code posted by Alexandra Barros a few days
ago. I have a situation where only 2 out of 3 userdata objects are
getting collected when I am finished with them. In the code below, only
s.themePanel and s.subthemePanel are collected. So I added the calls to
countreferences. It reports only 1 reference for all 3 objects I don't
see why the objects are not all collected after I set what I thought is
the only reference to nil.

I know there are some closures which have the panel objects as upvalues.
All these closures are held within other userdata objects that are
children of the objects I am trying to kill. So perhaps these circular
references (child has reference to parent which prevents collection of
parent) are blocking the collection. But in this case I thought that
countreferences would give me the count of the references caused by
these closures.

local function themeOnDeactivate(s, mm)
	-- Note that "printLine" simply appends a newline then calls
	printLine("monthPanel refs: "..gc.countreferences(s.monthPanel))
	printLine("themePanel refs: "..gc.countreferences(s.themePanel))
	printLine("subthemePanel refs:
	-- gc.countreferences returns 1 for all 3 objects
	-- therefore I expect the following to cause all 3 objects to be
	s.monthPanel = nil
	s.themePanel = nil
	s.subthemePanel = nil

Are there any suggestions as to why countreferences reports just one
reference but the object does not get collected when I set that
reference to nil?