I found that it is not allowed to call shared\_from\_this in the destructor from a class:

<https://svn.boost.org/trac/boost/ticket/147>

> 
> This behavior is by design. Since the destructor will destroy the object, it is not safe to create a shared\_ptr to it as it will become dangling once the destructor ends.
> 
> 
> 

I understand the argument, but what if I need a "shared\_from\_this" pointer for cleaning up references ( not for sharing owner ship).

Here is an example where I'm not using shared\_ptr:

```
class A{
public:
    A( Manager * m ) : m_(m) {
        m_->add(this);
    }

    ~A() {
        m_->remove(this);
    }

private:
    Manager * m_;
};

```

Here I have tried to translate it into shared pointers. But I can not find a good way to finish the destructor:

```
class A : public boost::enable_shared_from_this< A > {
public:
    typedef boost::shared_ptr< A > Ptr;

    static Ptr create( Manager * m ) {
        Ptr p( new A(m));
        p->init();
        return p;
    }

    ~A() {
        // NON-WORKING
        // m_->remove( shared_from_this() );
    }

private:
    A( Manager * m ) : m_(m) { }

    void init() {
        m_->add(shared_from_this());
    }

    Manager * m_;
};

```

How can I implement the destructor in the example above?