Skip to content

Commit e0d2e0a

Browse files
author
Roberto De Ioris
authored
Update MemoryManagement.md
1 parent cb96c5f commit e0d2e0a

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

docs/MemoryManagement.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,34 @@ Traceback (most recent call last):
4545
File "<string>", line XX, in <module>
4646
Exception: PyUObject is in invalid state
4747
```
48+
49+
Very long scripts, that do lot of stuff, often triggering UE4 GC, could be blocked in the middle of their execution by this kind of errors. In such a case (like you would do in C++) you need to inform the UE GC on how to deal with them (for avoiding their destruction).
50+
51+
Pay attention, as once you tell the UE GC to not destroy a UObject, that UObject (and its python mapping) will stay in memory (so you will end with a leak)
52+
53+
## Strategy 1: Setting UObject flags to govern the GC
54+
55+
When you create a UObject (from the C++ side, via the NewObject<T> api call) you can specify a bitmask of flags. By default the python api only use the RF_Public flag:
56+
57+
https://api.unrealengine.com/INT/API/Runtime/CoreUObject/UObject/EObjectFlags/index.html
58+
59+
You can change this bitmask with the set_obj_flags() python function:
60+
61+
```python
62+
import unreal_engine as ue
63+
64+
from unreal_engine.classes import BlueprintFactory
65+
66+
factory = BlueprintFactory()
67+
# assign mask 0x00000001|0x00000002
68+
factory.set_obj_flags(ue.RF_PUBLIC|ue.RF_STANDALONE)
69+
# run GC
70+
ue.console_exec('obj gc')
71+
# this will normally print the UObject repr
72+
print(factory)
73+
```
74+
75+
The RF_Standalone flag (RF_STANDALONE in python api) will marks a UObject as 'standalone' so it will remain resident in memory forever.
76+
This is a pretty raw approach (unless you are sure that you need a resident object). For having more control the second strategy will be way more better...
77+
78+
## Strategy 2: The Root Set

0 commit comments

Comments
 (0)