I read that Unreal Engine 's Garbage Collection of UOBJECT relies on Reflection.
Does that mean that this code is unsafe?
void AMyActor::MyFunction()
{
MyGCType* LocalObject = NewObject<MyGCType>();
for (int i = 0; i < 1 000 000; i++)
{
LocalObject->DoSomething();
}
}
If this piece of code is unsafe, does it mean we cannot make use of locally-scoped UOBJECT?
I haven’t run into any problems with this.
GC will delete such object every 60 seconds, for more safety simply destroy object when you done with it or place it in UPROPERTY() variable for feather use.
You could also think of using non-UObject or struct for this, which wont have any UObject control code that might only slow such short lived object, the you simply use “new” and “delete” operators to create and delete object, you need to “delete” such object or else it will stay in memory forever
Thank you this really helped. I was just reading the tutorial and this hypothetical question comes to mind. Indeed I will avoid ever using local UOBJECT. Thanks! : D
Thanks for the testing! : D