当前位置:网站首页>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
边栏推荐
- Enlist soldiers and generals, draw small programs, multi-threaded display time
- Solution to 293 problems in the week of Li Kou
- 【Paper】2015_ Active fault-tolerant control system design with trajectory re-planning against actuator
- Output directory of log files after unity3d packaging
- 為什麼win10開熱點後電腦沒有網絡?
- Malignant bug: 1252 of unit MySQL export
- 力扣周赛293题解
- What is SQL injection and how to avoid it?
- Connect to the database and run node JS running database shows that the database is missing
- z-index属性在什么情况下会失效?
猜你喜欢

National Museum of Singapore - give you spiritual and physical satisfaction
![[UAV] gyroscope data analysis, taking Victor intelligent jy901b as an example](/img/d7/7bf43437edb87b69cdc5ae858f44e1.jpg)
[UAV] gyroscope data analysis, taking Victor intelligent jy901b as an example

redis集群概念

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

Meet in Bangkok for a romantic trip on Valentine's Day

力扣977. 有序数组的平方

Connect to the database and run node JS running database shows that the database is missing

Deeply understand the function calling process of C language

Output directory of log files after unity3d packaging

Unreal 4 unavigationsystemv1 compilation error
随机推荐
【Paper】2017_ Research on coordinated control method of underwater vehicle formation marine survey
How to repair expired SSL certificates?
Lambda&Stream
IIS request SSL certificate
Solution to the 292 week match of Li Kou
力扣27. 移除元素
JS 数组的排序 sort方法详解
C # Foundation
Force buckle 349 Intersection of two arrays
[control] multi agent system summary. 1. system model. 2. control objectives. 3. model transformation.
力扣209. 长度最小的子数组
Recommended cultural landmarks of these tourist attractions in Bangkok
The difference between get and post requests
Encapsulating JDBC tool classes
UE4 method of embedding web pages
Difference between request forwarding and redirection
SSL universal domain name certificate
力扣2049:统计最高分的节点数目
The most comprehensive summary notes of redis foundation + advanced project in history
【Paper】2021_ Uniformity of heterogeneous hybrid multi-level intelligent systems using UGV and UAV