M
Miguel Guedes
I'd like some clarification on the correct way to destroy an object.
I've seen a couple of open source projects make use of object factories to
instantiate classes and smart pointers to destroy them when the ref_count
reaches zero. Something like:
pInstance = Factory::createSomething();
{
smart_ptr<Something> ptr = pInstance
.
:
}
// out of scope: smart_ptr destroys pInstance
My question is, isn't a creator entity supposed to be responsible for the
destruction of the objects it creates? Isn't this one of the golden rules of
correct OO code design and what RAII is all about?
Would appreciate some clarification on this. Thank you.
I've seen a couple of open source projects make use of object factories to
instantiate classes and smart pointers to destroy them when the ref_count
reaches zero. Something like:
pInstance = Factory::createSomething();
{
smart_ptr<Something> ptr = pInstance
.
:
}
// out of scope: smart_ptr destroys pInstance
My question is, isn't a creator entity supposed to be responsible for the
destruction of the objects it creates? Isn't this one of the golden rules of
correct OO code design and what RAII is all about?
Would appreciate some clarification on this. Thank you.