Re: Another collectgarbage question. (Inherited class)

Jason McKesson <[email protected]>
Newsgroups gmane.comp.lang.lua.bind.user
Message-ID <[email protected]>
Taesoo Kwon wrote:
> Hello,
>
> I am using luabind 0.8.1, lua5.1.4, MSVC2005.
> I have an example where garbage collection doesn't work for a derived 
> lua class.
> Is this a normal behavior? What should I modify?
>
> class 'VVV'
>
> function VVV:__init()
>    print("ctor VVV")
> end
>
> function VVV:__finalize()
>    print("dtor VVV")
> end
>
>
> class 'GCtest'
>
> function GCtest:__init()
>    self.skel=VVV()
> end
>  
> class 'GCtest2'(GCtest) -- derived class
> function GCtest2:__init()
>    GCtest.__init(self)
> end
>
> function gctest()
>    do
>       local test=GCtest()  
>    end
>    collectgarbage() -- dtor of VVV is called.
>    collectgarbage()
>    collectgarbage()
>
>    do
>       local test=GCtest2()
>    end
>    collectgarbage()
>    collectgarbage()
>    collectgarbage() -- dtor of VVV is not called.
>
> end
>
> Thank you.
> ------------------------------------------------------------------------
>
> ------------------------------------------------------------------------------
> Come build with us! The BlackBerry&reg; Developer Conference in SF, CA
> is the only developer event you need to attend this year. Jumpstart your
> developing skills, take BlackBerry mobile applications to market and stay 
> ahead of the curve. Join us from November 9&#45;12, 2009. Register now&#33;
> http://p.sf.net/sfu/devconf
> ------------------------------------------------------------------------
>
> _______________________________________________
> luabind-user mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/luabind-user
>   
It is Lua that decides when the finalize method of a table will be 
called. It will do it eventually, but it does not guarantee that it will 
be called at any particular time. And if Lua's garbage collection 
functions don't want to do a full CG on everything in memory when you 
call the function, then there's nothing you can do.

This is the price you pay for having a fast garbage collector.

------------------------------------------------------------------------------
Come build with us! The BlackBerry&reg; Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9&#45;12, 2009. Register now&#33;
http://p.sf.net/sfu/devconf
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.