The last shared_ptr to an object triggers deletion. When that final shared_ptr's destructor runs or is reset, the reference count hits zero and delete is called on the managed object.
You don't control exactly when this happens. It's whenever the last owner dies. In complex code with many copies, tracking the final owner manually would be nearly impossible. This automatic deletion prevents leaks but can surprise you with destruction timing.
Don't rely on exact destruction order for shared_ptr objects. Let go of control and trust the count.