On Wed, Dec 19, 2007 at 01:21:10PM +0100, STenyaK (Bruno Gonzalez) wrote:
Ok. This is how my code structure looks: ---------------------------- typedef shared_ptr<MyClass> pMyClass; void* MyClass::actionThread(void *objectPointer) { pMyClass * _obj = static_cast
(objectPointer); pMyClass obj = *_obj; obj->action(false); delete _obj; }
It is _crucial_ to call delete BEFORE any other action in the code, or else you may suffer memory leak (consider e.g. that action throws an exception). Otherwise, your interpretation seems correct.
Do i need to use enable_shared_from_this? Or do i have to avoid using "this" (orig_ptr in your code) somehow maybe?
Uf, I don't know. Read this: http://www.boost.org/libs/smart_ptr/sp_techniques.html it mentiones several instances of the "shared_ptr from this" problem.