Greetings! )
I’m trying to understand how to work with SharedPtr correctly and stumbled upon an indefinite behavior that put me in a dead end. It is expected that after deleting an object, the number of links will decrease, but this does not happen.
In general, I would very much like not to use SharedPtr in my project, but to work with objects directly. But as I understand it, CreateChild/CreateComponent, in addition to constructing objects, also performs various bindings that are not performed in object constructors, that is, the part of object initialization is taken out of an object …
How safe will it be to not use SharedPtr/CreateComponent?
I still don’t understand why you call delete on m_rootNode. That’s not a pointer and I’m not even sure why the compiler let you do that. You’re supposed to Release() your reference and let the smart pointer do it’s job.
As for why the counters become that value. You should look at the destructor of RefCounted.
You would only use delete if the shared pointer itself would be dynamically allocated. Like Urho3D::SharedPtr<Urho3D::Node>* m_rootNode; and not Urho3D::SharedPtr<Urho3D::Node> m_rootNode;. Notice the *.
So based on that macro. I assume this line delete _name; becomes delete m_rootNode;. And m_rootNode is not a pointer.
and in result i have 3 refs to pointer. But i can not rtemove my model from m_parentBlock->collisionShape() ( Urho3D::CollisionShape) and m_parentBlock->model() (Urho3D::StaticModel). How i can there reset refs?