Luabind and boost::shared_ptr<T> use counts

Patrick Hartling <[email protected]>
Newsgroups gmane.comp.lang.lua.bind.user
Message-ID <[email protected]>
I am trying to understand how Luabind handles boost::shared_ptr<T> objects. Specifically, the use count for any boost::shared_ptr<T> passed to a Lua function is incremented during the function execution but not decremented once the function call completes. This leads to memory leaks if there is an expectation of the use count on these objects eventually reaching zero.

The attached program demonstrates what I am seeing. If the shared pointer-wrapped object is wrapped in boost::ref() before being passed to Luabind (see line 72), then the use count works out correctly. Is this the correct way to use boost::shared_ptr<T> with Luabind, or is there a preferred practice? In general, I think it will be fine use to use boost::ref() as long as we are careful.

I tested with Luabind 0.8.1, Boost 1.43, and Lua 5.1.4 on Mac OS X 10.6. The same behavior occurs on Linux.

 -Patrick


--
Patrick L. Hartling
Senior Software Engineer, Priority 5
http://www.priority5.com/

------------------------------------------------------------------------------

_______________________________________________
luabind-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/luabind-user
lua_test.cpp (application/octet-stream, 1.7 KB) - not displayed
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.