luabind - problem with luabind::object reference

classic Classic list List threaded Threaded
3 messages Options
kFk
Reply | Threaded
Open this post in threaded view
|

luabind - problem with luabind::object reference

kFk
Using C++, lua5.1, luabind 0.7

*** Lua code: ***
-- allocates near 8Mb of memory
function fff()
    local t = {}
    for i = 1, 300000 do
        table.insert(t, i)
    end
    return t
end

*** C++ code ***
{
    luaL_dostring(lua_state, "return fff()");
    luabind::object obj(luabind::from_stack(ls, -1));
}
lua_gc(l_, LUA_GCCOLLECT, 0); // collect garbage

Result: Lua still have a 8Mb allocated memory. Garbage collection ignores that table object. It has references anywhere? But where? That table deallocates only on program exit (when "lua_close" function called). How to solve this problem and what is the reason?

Thank you.

------------------------------------------------------------------------------
This SF.Net email is sponsored by the Verizon Developer Community
Take advantage of Verizon's best-in-class app development support
A streamlined, 14 day to market process makes app distribution fast and easy
Join now and get one step closer to millions of Verizon customers
http://p.sf.net/sfu/verizon-dev2dev 
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: luabind - problem with luabind::object reference

Linker
 luabind::object obj(luabind::from_stack(ls, -1));
The "obj" hold a ref.

On Sun, Dec 20, 2009 at 18:25, Oleksandr . <[hidden email]> wrote:
Using C++, lua5.1, luabind 0.7

*** Lua code: ***
-- allocates near 8Mb of memory
function fff()
    local t = {}
    for i = 1, 300000 do
        table.insert(t, i)
    end
    return t
end

*** C++ code ***
{
    luaL_dostring(lua_state, "return fff()");
    luabind::object obj(luabind::from_stack(ls, -1));
}
lua_gc(l_, LUA_GCCOLLECT, 0); // collect garbage

Result: Lua still have a 8Mb allocated memory. Garbage collection ignores that table object. It has references anywhere? But where? That table deallocates only on program exit (when "lua_close" function called). How to solve this problem and what is the reason?

Thank you.

------------------------------------------------------------------------------
This SF.Net email is sponsored by the Verizon Developer Community
Take advantage of Verizon's best-in-class app development support
A streamlined, 14 day to market process makes app distribution fast and easy
Join now and get one step closer to millions of Verizon customers
http://p.sf.net/sfu/verizon-dev2dev
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user




--
Regards,
Linker Lin
[hidden email]

------------------------------------------------------------------------------
This SF.Net email is sponsored by the Verizon Developer Community
Take advantage of Verizon's best-in-class app development support
A streamlined, 14 day to market process makes app distribution fast and easy
Join now and get one step closer to millions of Verizon customers
http://p.sf.net/sfu/verizon-dev2dev 
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: luabind - problem with luabind::object reference

Jason McKesson
Yes, the object has a reference. However, the object should releases the reference when it is destroyed. Which happens immediately after creation.

No, his problem is the fact that the object is still on the stack. Luabind's from_stack call does not pop it off of the stack for you; you have to do that yourself.

On 12/20/2009 9:30 AM, Linker wrote:
 luabind::object obj(luabind::from_stack(ls, -1));
The "obj" hold a ref.

On Sun, Dec 20, 2009 at 18:25, Oleksandr . <[hidden email]> wrote:
Using C++, lua5.1, luabind 0.7

*** Lua code: ***
-- allocates near 8Mb of memory
function fff()
    local t = {}
    for i = 1, 300000 do
        table.insert(t, i)
    end
    return t
end

*** C++ code ***
{
    luaL_dostring(lua_state, "return fff()");
    luabind::object obj(luabind::from_stack(ls, -1));
}
lua_gc(l_, LUA_GCCOLLECT, 0); // collect garbage

Result: Lua still have a 8Mb allocated memory. Garbage collection ignores that table object. It has references anywhere? But where? That table deallocates only on program exit (when "lua_close" function called). How to solve this problem and what is the reason?

Thank you.

------------------------------------------------------------------------------
This SF.Net email is sponsored by the Verizon Developer Community
Take advantage of Verizon's best-in-class app development support
A streamlined, 14 day to market process makes app distribution fast and easy
Join now and get one step closer to millions of Verizon customers
http://p.sf.net/sfu/verizon-dev2dev
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user




--
Regards,
Linker Lin
[hidden email]
------------------------------------------------------------------------------ This SF.Net email is sponsored by the Verizon Developer Community Take advantage of Verizon's best-in-class app development support A streamlined, 14 day to market process makes app distribution fast and easy Join now and get one step closer to millions of Verizon customers http://p.sf.net/sfu/verizon-dev2dev
_______________________________________________ luabind-user mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/luabind-user


------------------------------------------------------------------------------
This SF.Net email is sponsored by the Verizon Developer Community
Take advantage of Verizon's best-in-class app development support
A streamlined, 14 day to market process makes app distribution fast and easy
Join now and get one step closer to millions of Verizon customers
http://p.sf.net/sfu/verizon-dev2dev 
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user