当前位置:网站首页>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
边栏推荐
- 【Paper】2021_ Uniformity of heterogeneous hybrid multi-level intelligent systems using UGV and UAV
- Wildcard SSL certificate issuing time
- Unreal 4 unavigationsystemv1 compilation error
- Detailed explanation of the process of "flyingbird" small game (camera adjustment and following part)
- 力扣977. 有序数组的平方
- Dual domain SSL certificate
- z-index属性在什么情况下会失效?
- Unit screenshot saved on the phone
- IO stream, byte stream read / write copy
- Unreal 4 learning notes - Animated Montage
猜你喜欢

Universal Studios Singapore: a good place for a one-day parent-child tour in Singapore

Qos(Quality of Service)

MySQL查询小工具(一)json格式的字符串字段中,替换json数组中对象的某个属性值

Spring Festival Tourism Strategy: welcome the new year in Bangkok, Thailand

力扣589:N 叉树的前序遍历

Pourquoi l'ordinateur n'a - t - il pas de réseau après l'ouverture du Hotspot win10?

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

Dual domain SSL certificate

Moore Manor diary I: realize the reclamation, sowing, watering and harvest in Moore Manor

Redis implements SMS login function (II) redis implements login function
随机推荐
PBR material: basic principle and simple fabrication
How to repair expired SSL certificates?
Unity3d lookat parameter description
One interview question a day the difference between B tree and b+ tree
【Paper】2017_ Distributed control for high-speed trains movements
Steamvr causes abnormal scene camera
brew安装nvm报nvm command not found解决方案
harbor api 2.0查询
力扣349. 两个数组的交集
The role of break
【Paper】2021_ Uniformity of heterogeneous hybrid multi-level intelligent systems using UGV and UAV
A collection of errors encountered in machine learning with unity
Issue SSL certificate with IP address
【Paper】2013_ An efficient model predictive control scheme for an unmanned quadrotor helicopter
UE4 method of embedding web pages
Detailed explanation of the process of "flyingbird" small game (camera adjustment and following part)
Unity lens making
Harbor API 2.0 query
Lambda&Stream
JPA composite primary key usage