Object memory management

If I dynamicaly create UImage in my code, should I delete them when they are not needed, or UE grabage collector will cleanup them for me?

my code

Image = NewObject<UImage>(UImage::StaticClass());


I attach them to Canvas Panel after creation. Will the be gone with the Panel, or I should delete them at EndPlay?
And how should I delete them, with delete operator or there is some function for this?

GC will destroys all UObjects that are not refrenced in any reflected pointer varable (marked with UPROPERTY()) every minute. But its nothing wrong to clean things for yourself :slight_smile:

What about nonreflected properties? Should I use smartpointers?
I am storing UImage pointers in TMap associating them to AActor objects.
So while HUD is always holding refernces to UImage’s im ok. But it is only a matter of time when things will go wrong.

Engine don’t see nonreflected properties, so object will get collected and pointer will be invalid, i think TSheredPtr should work

About TMap, reflection system don’t see them either, i find this thred maybe it will help?

Keep in mind that only UObjects get garbage collected, if you ever cross pointers to diffrent types or non-UObject classes, those needs to be cleaned manually

Thanks, man, for the comprehensive answer. You are the best.
I will recheck pointer usage in my project.