weak_ptr
A `weak_ptr` is a smart pointer in C++ that helps manage the lifetime of dynamically allocated objects without taking ownership. It is part of the C++ Standard Library and is used in conjunction with `shared_ptr`. While `shared_ptr` keeps track of how many pointers point to an object, `weak_ptr` allows access to that object without increasing the reference count, preventing circular references that can lead to memory leaks.
When a `shared_ptr` is created, a `weak_ptr` can be associated with it. If the `shared_ptr` is destroyed, the `weak_ptr` becomes invalid, but it does not prevent the object from being deleted. This makes `weak_ptr` useful for scenarios like caching or observer patterns, where you want to reference an object without affecting its lifetime.