std::weak_ptr
`std::weak_ptr` is a smart pointer in C++ that provides a non-owning reference to an object managed by a `std::shared_ptr`. It allows you to observe an object without affecting its reference count, preventing circular references that can lead to memory leaks. When the last `std::shared_ptr` to an object is destroyed, the object is deleted, and `std::weak_ptr` becomes invalid.
To access the object, you can convert a `std::weak_ptr` to a `std::shared_ptr` using the `lock()` method. If the object still exists, `lock()` returns a valid `std::shared_ptr`; otherwise, it returns an empty pointer. This mechanism ensures safe access to shared resources.