Use weak_ptr<> to manage lifetimes correctly.