// Set up a viewport to the Renderer subsystem so that the 3D scene can be seen
SharedPtr<Viewport> viewport(new Viewport(context_, scene_, cameraNode_->GetComponent<Camera>()));
renderer->SetViewport(0, viewport);
}
[/code] SharedPtr viewport is local variable SharedPtr viewport convert to raw pointer Viewport* (reference count not increased) and used in SetViewport() SharedPtr viewport deleted as local variable (reference count == 0)
Why Viewport* is not destroyed?
Yes, it automatizes strong refcount management, so that you don’t have to do manual calls to increment / decrement it.
Intrusive shared pointers may be strange at first to someone coming from a std::shared_ptr background, but once you understand how they work, there should be relatively few ways to shoot yourself in the foot with them. The tendency of API functions to store shared pointers internally is documented in the conventions: