lua-users home
lua-l archive

Re: coroutines local userdata and GC

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


It was thus said that the Great arioch82 once stated:
> Hi,
> 
> first of all sorry for the long email but i could really use some help
> here...
> 
> i am running lua 5.1 in a C++ environment and i am having a problem with
> some user data not being garbage collected and i have been trying to figure
> out why for a while without much luck.
> 
> the following code is all abstracted but the flow is representative of
> production code, some of this may look weird without context but please i am
> not looking to any comment on code design, just trying to understand how the
> userdata/GC works when you have local references inside coroutines
 [ code snipped ]
> function exit()
> tableref = nil
> end
 Setting a userdata to nil doesn't cause the GC to run immediately
(although it will eventually be called). As a test of your __gc() method on
"myref", try the following:
	function exit()
	 tableref = nil
	 collectgarbage('collect')
	end
 Calling collectgarbag() will force a GC cycle. If it is reclaimed, then
you have two choices: either just wait for Lua to run a GC cycle with the
understanding that it's not always immedate, or force a GC cycle.
 If it's not collected, then you are leaking references somewhere.
 -spc (Chasing down stray references isn't fun ... )

AltStyle によって変換されたページ (->オリジナル) /