Re: double deletion problem with shared pointers.
Daniel Wallin <[email protected]>
| Newsgroups | gmane.comp.lang.lua.bind.user |
|---|---|
| Message-ID | <[email protected]> |
Nigel Atkinson wrote: > The attached code shows the double deletion problem I encounted. I > previously thought that the problem only surfaced when using the > shared_ptr_converter. However it looks like it happens either way. Right. This fails because the widget_wrapper instance that corresponds to your Lua widget instance is held in a global shared_ptr, which is destructed after the Lua state is destroyed. widget_wrapper will hold a weak back reference to the Lua instance, so that it can call back to overridden functions in Lua. When it is destructed it will clean up the weak reference, and in this case that means accessing a destroyed Lua state. shared_ptr_converter has the same problem. It stores a back reference to the Lua instance, keeping it alive so that you don't get the slicing you encountered, and when it's destructed it cleans that up. AFAIK there's really no way around this. You need to ensure that you don't destroy the Lua state while you still have references to Lua objects around. -- Daniel Wallin BoostPro Computing http://www.boostpro.com ------------------------------------------------------------------------------ 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