[Solved] Another collectgarbage question. (Inherited class)

Taesoo Kwon <[email protected]>
Newsgroups gmane.comp.lang.lua.bind.user
Message-ID <[email protected]>
Nigel Atkinson sent me an e-mail regarding this issue. It worked, so I am
attaching it here for those who experience a similar problem. Thanks!
-------------------------------------------------------------------------------------------------
I hit the same situation.  As it turns out when you make an instance of a
Lua class, that has a base class, it makes a global called 'super'.  This
was for the old method of calling the base constructor.  I think you will
find it is only the *last* instance (that fits the above description)
created that is affected.

So doing:

super = nil

before collecting garbage, it should work.  I personally commented out the
C++ code that makes the 'super' global, as its use is now depreciated.

Hope this helps!

--

Nigel Atkinson
[email protected]


On Wed, Sep 23, 2009 at 5:38 PM, Taesoo Kwon <[email protected]> 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()  -- <<< <  add "super=nil" after here. Then dtor
> of VVV is called.
>
   end
>    collectgarbage()
>    collectgarbage()
>    collectgarbage() -- dtor of VVV is not called.
>
> end
>
> Thank you.
>

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july

_______________________________________________
luabind-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/luabind-user
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.