Hello Guys,
I’m still working on memory management for our game and I wonder something.
Does Unreal is supposed to destroy automaticallyUPROPERTY()
marked childrens objects (Actor or Object) pointers upon their destruction ?
Consider the folowing code :
.h
class AGame_API ADummyActor : public AActor
{
GENERATED_BODY()
public:
ADummyActor(const FObjectInitializer& ObjectInitializer);
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = Dummy)
UTexture* texture;
void SetTexture();
};
.cpp
ADummyActor::ADummyActor(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer)
{
texture = nullptr;
}
void ADummyActor::SetTexture()
{
texture = LoadObject<UTexture>(this, TEXT("/Game/Menu/Artwork/toto/Background_fantasy.Background_fantasy"), NULL, LOAD_None, NULL);
}
This code would be the same for a UObject derived object.
For this case, assume that I no (0) instance of the DummyActor and I have a button to spawn an instance and another to destroy that very same instance. Also, assume that the texture is not referenced anywhere else.
When I call delete upon the button, is it supposed to also destroy the texture pointer and release the memory associated with the texture ?
If YES, that doesn’t work at all.
If NO, should I declare a ClearChildrens function that will manually delet every childrens data ? or what sould I do ?
I mean in raw C++ there’s no garbage, so I’m well used to clean childrens memory upon destructor call.
But with Unreal, we are supposed to have a garbage collector that is supposed to clean unused memory right ?
Or am I crazy and missed something o0 ?
Thanks for any help…
gamer08