Boost logo

Boost Users :

Subject: [Boost-users] [shared_ptr] boost::shared_ptr deleter question
From: Tamas.Ruszkai_at_[hidden]
Date: 2015-08-14 05:07:53


Hi All,

I wonder when the shared_ptr deleter is destroyed.

I have a shared_ptr with a custom deleter. I would expect when the last
shared pointer to the object is gone then not only the deleter method will
be called, but the deleter function object is also released. As I see the
deleter is taken by value and stored by value in the reference counter, so
I do not understand what is going on.

How is the deleter mean to be freed?

Thanks,
Tamas

struct MyClassDeleter
{
        ~MyClassDeleter()
        {
                // Break point is set here
        }

        void operator()(MyClass* item)
        {
                // Break point is set here
        }
}

{
        auto sharedPtr = boost::shared_ptr<MyClass>(new MyClass,
MyClassDeleter)
}

// shared_ptr leaves the scope here, the custom deleter is called
(parenthesis operator)
// the deleter instance is however not destroyed, the breakpoint in the
destructor does not hit



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