Normal pointer or SharedPtr?

Is strictly necessary to use SharedPtr?
Is It wrong to use normal pointers?

Thanks :wink:

Yes/No and no.

Shared pointers are great because you will know if an object is deleted before the pointer, and it prevents some relatively bad issues as a result. However it is fine to use normal pointers as long as you pay attention.

Do note that you will want to keep a SharedPtr to an object as long as you want that object to stay alive. Otherwise you run into the possibility of the object getting deleted when the last SharedPtr pointing to it gets deleted. However beyond that, you can freely use normal points as much as you want.

Thank you very much! :slight_smile:

[quote=“thebluefish”]Yes/No and no.

Shared pointers are great because you will know if an object is deleted before the pointe

Do note that you will want to keep a SharedPtr to an object as long as you want that object to stay alive. Otherwise you run into the possibility of the object getting deleted when the last SharedPtr pointing to it gets deleted. However beyond that, you can freely use normal points as much as you want.[/quote]

A related question is that, is there a reason not to use the C++ std::shared_ptr<> but a custom implementation in Urho3D?

The SharedPtr questions have been asked a few times already in the forum. The most recent one is this. topic1723.html. Urho3D SharedPtr uses intrusive refcounting.

From Urho3D documentation urho3d.github.io/documentation/H … tions.html :