UE4的智能指針TSharedRef, TSharedPtr, TWeakPtr的實(shí)現(xiàn)方式類似于C++11中的shared_ptr、weak_ptr的實(shí)現(xiàn)。通過shared、weak組合使用來避免循環(huán)引用(導(dǎo)致內(nèi)存泄漏)。
相關(guān)源碼:
Engine\Source\Runtime\Core\Public\Templates\SharedPointerInternals.h Engine\Source\Runtime\Core\Public\Templates\SharedPointer.h
實(shí)現(xiàn)方式圖解:

UE4_Smart_Pointer.jpg