There is such code:

_object = std::shared_ptr<Object>(new Object()); 

If it took me an object to become empty, then I would do this:

 _object = nullptr; 

And then again I want to use this variable and call it again.

 _object = std::shared_ptr<Object>(new Object()); 

Question: Will there be a memory leak and is it right to do this?

    1 answer 1

    Leakage will not be where to take it? It is better to create std::shared_ptr using std::make_shared , this allows you to have a block of reference counting and the data itself in one piece in memory. Those. The code will look like this:

     _object = std::make_shared<Object>();