Smart pointer lifetime

17 views
Skip to first unread message

Shachar Langbeheim

unread,
Aug 28, 2019, 6:51:35 AM8/28/19
to emscripten-discuss
Hi,
The Embind page states "To manage object lifetime with smart pointers, embind must be told about the smart pointer type", but I've created an object using a smart pointer constructor and once the JS object is removed, the object's destructor wasn't called. 

This isn't surprising considering the prior statement "[...] 
there is no way for Emscripten to automatically call the destructors on C++ objects.", so it makes sense that Emscripten cannot call the smart pointer destructor. But, if smart pointers destructors aren't called, but the pointers' share count is incremented during their construction, the shared_ptr will never release its contained object. That is, while I could add a custom deleter for a raw pointer, I couldn't do that for a smart pointer.

Which statement is true? Do smart pointers manage the lifetime of the internal objects, or they don't? 

Reply all
Reply to author
Forward
0 new messages