fix memory leak by weak_ptr