当前位置:网站首页>Unrealeengine4 - about uobject's giant pit that is automatically GC garbage collected
Unrealeengine4 - about uobject's giant pit that is automatically GC garbage collected
2022-06-30 04:52:00 【Answer-3】
1 What happened
A static inheritance is created in a plug-in UObject The object of
static UMyObject* m_Object = nullptr;
1
Then it is initialized in the blueprint function of the plug-in :
m_Object = NewObject<UMyObject>();
1
After some time, it is found that this object is destructed , Lead to wild pointer , Cause program crash !
This NIMA is a static object pointer !
2 UE4 Yes UObject Automatic destructor mechanism of
UE4 Yes UObject The object is not like C++,UE4 Will be in UObject Automatically reclaim an object when it has no reference .( So smart , Intelligent makes people's scalp numb )
and C++ If the object is dynamically created, it will always exist in the declaration cycle of the program , If you don't actively destruct , Will cause memory leaks .
On the bright side UE4 This mechanism for preventing memory leaks is perfect , But for those who have just come into contact UE4 For the novice , expected sth. to happen UE4 Adopted C++, But the mechanism is really so different , It is easy to cause the problem of wild pointer .
3 keep UObject Objects are not automatically destructed
If in the ordinary C++ There is one in the class UObject* A Variable , After creating this variable , Best use AddToRoot, In this way, it will not be UE4 Automatically GC, Then in the destructor , Use RemoveFromRoot Can automatically make UE4GC, Prevent memory leaks .
UMyObject* m_Object = NewObject<UMyObject>();
m_Object->AddToRoot();
1
2
And then in C++ Class destructor :
m_Object->RemoveFromRoot();
1
If you are inheriting UObject There is one in the class UObject* A Variable , Then you can use UPROPERTY Macro mark this variable , Then this variable will not be UE4 Automatically GC, When the class is destroyed , Variable A Will be set to null, After that UE4 Automatically GC.
————————————————
Copyright notice : This paper is about CSDN Blogger 「HW140701」 The original article of , follow CC 4.0 BY-SA Copyright agreement , For reprint, please attach the original source link and this statement .
Link to the original text :https://blog.csdn.net/HW140701/article/details/110149812
边栏推荐
- Using the command line to convert JSON to dart file in fluent
- 力扣周赛293题解
- 【Paper】2013_ An efficient model predictive control scheme for an unmanned quadrotor helicopter
- HTC vive cosmos development - handle button event
- Detailed explanation of the process of "flyingbird" small game (camera adjustment and following part)
- Some books you should not miss when you are new to the workplace
- Steamvr causes abnormal scene camera
- Marvel fan welfare: Singapore Madame Tussauds Wax Museum Marvel 4D experience Museum
- One interview question and one joint index every day
- Unity script life cycle and execution sequence
猜你喜欢

Unity3d lookat parameter description

Collective system

Qos(Quality of Service)

Unity lens making
![[UAV] kinematic analysis from single propeller to four rotor UAV](/img/32/1a88b102f832ffbbc1a7e57798260a.jpg)
[UAV] kinematic analysis from single propeller to four rotor UAV

SCM learning notes: interrupt learning

MySQL query gadget (I) replace a property value of the object in the JSON array in the JSON format string field

【Paper】2015_ Coordinated cruise control for high-speed train movements based on a multi-agent model

力扣704. 二分查找

Redis实现短信登入功能(一)传统的Session登入
随机推荐
Sectigo certificate
Lambda&Stream
Error about the new version of UE4: unavigationsystemv1:: simplemovetoactor has been deprecated
Software digital signature certificate
Deeply understand the function calling process of C language
The subsystem implementing transaction persistence in DBMS is ()
Serializable and Deserialize
Collective system
【Paper】2017_ Research on coordinated control method of underwater vehicle formation marine survey
Differences between cookies and sessions
National Museum of Singapore - give you spiritual and physical satisfaction
MySQL query gadget (I) replace a property value of the object in the JSON array in the JSON format string field
Singapore parent-child tour, these popular attractions must be arranged
Using the command line to convert JSON to dart file in fluent
C # Foundation
Yolov5 torch installation
Redis implements SMS login function (I) traditional session login
Oculus quest2 development: (I) basic environment construction and guide package
Qos(Quality of Service)
One interview question a day the difference between B tree and b+ tree