Re: Discarding shared_ptrs
Nigel Atkinson <[email protected]>
| Newsgroups | gmane.comp.lang.lua.bind.user |
|---|---|
| Message-ID | <1307401843.1601.13.camel@virNatty> |
If you keep a reference around in Lua you will have a use count for it. You can set to nil to remove that reference but you need make sure you set all references to that pointer to nil. A slight gotcha is that Lua will only increase the count by 1 regardless of how many references in Lua you have. Kinda obvious if you think about it for a moment, but not so obvious if are thinking about other things! You could use a weak table in Lua if you don't want Lua to 'hold on' to shared pointers, or perhaps you could actually use a boost::weak_ptr ( I haven't tried this.) Depends what you are doing. For instance I use a "ward ptr" for some things, which basically is a smart pointer that can be marked as invalid so later on if Lua tries to use it, it throws an exception/Lua error rather than crashing. Which is nice. :-P HTH Nigel On Mon, 2011-06-06 at 22:40 +0100, Simon Pickles wrote: > Hi, > > I am passing boost::shared_ptr<T> to Lua functions, which works well. > > Unfortunately, the shared_ptr then keeps an extra use_count (held in the > lua table), even if the function is finished. How do I release this usage? > > Set to nil? Use a Policy? Pass some other sort of pointer? I'd love to > be able to use the functionality of boost::weak_ptr in lua! > > Any advice welcome > > thanks > > Simon > > > > ------------------------------------------------------------------------------ > EditLive Enterprise is the world's most technically advanced content > authoring tool. Experience the power of Track Changes, Inline Image > Editing and ensure content is compliant with Accessibility Checking. > http://p.sf.net/sfu/ephox-dev2dev > _______________________________________________ > luabind-user mailing list > [email protected] > https://lists.sourceforge.net/lists/listinfo/luabind-user ------------------------------------------------------------------------------ EditLive Enterprise is the world's most technically advanced content authoring tool. Experience the power of Track Changes, Inline Image Editing and ensure content is compliant with Accessibility Checking. http://p.sf.net/sfu/ephox-dev2dev