Pergunta de entrevista da empresa Squarepoint Capital

Explain two main usecases for weak_ptr<>.

Resposta da entrevista

Sigiloso

15 de nov. de 2025

1. When you have a collection that stores references to objects, sometimes you don't need those objects' lifetime to match that of your collection, so we can store them as weak references that don't contribute to the ref count, so that the collection doesn't own them, allowing them to get destroyed. 2. When you have objects referencing each other, non-weak smart pointers would result in a deadlock, and therefore a memory leak.