Declaration and Initialization
Weak pointers are always created from shared pointers/references, or other weak pointers.
// Allocate a new tree node.
TSharedRef<FTreeNode> NodeOwner( new FTreeNode() );
// Create a weak pointer to the new tree node.
TWeakPtr<FTreenode> NodeObserver( NodeOwner );
Remember, a weak pointer does not prevent the object from being destroyed. If NodeOwner is reset while NodeObserver is still in scope, the object will be deleted:
// Destroy the node.
Weak pointers can be copied around safely, just like shared pointers.
TWeakPtr<FTreeNode> NodeObserverB = NodeObserver;
You can reset (or reassign) a weak pointer when you are done with it.
NodeObserver = null;