add function to clean a weak_ptr container