|
Boost Users : |
From: Zeljko Vrba (zvrba_at_[hidden])
Date: 2007-12-19 09:41:04
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<pMyClass*>(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.
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net