Struct destroy and garbage collection

Hello.

I wanted to know if there was a way to destroy or delete structs from memory, and how unreal engine performs garbage collection for structs.

Do structs that have not been used, get purged from memory?

For example, I wish to make an ability system where I have structs for health, mana, stamina as:

struct FAttributeStruct {
    float value;
    float minimum_value;
    float maximum_value;
};

If I have values for health struct-variable in a character/Actor/ActorComponent, will the health struct be deleted from memory if not used, by the UE garbage collector?

Secondly, In this scenario, can I also make a TMap<FString, FAttributeStruct *>, such that I can map keys to FAttributeStruct pointers?
Will there be a case where dereferencing those pointers can yield a nullptr?

Thirdly, can I destroy structs similar to destroying actors or components?

Thanks in advance.

The engine does not garbage collect anything other than UObjects. If you create structs (or indeed, any data type) with new, you are responsible for deleting them. Even if you allocate a struct within a UObject, you must delete that data before the UObject is destroyed - the engine can’t and won’t do that for you.

Where appropriate, you can and normally should use Smart Pointers to make this simpler.

1 Like

it’s depend on how you create your sturct, if not use keyword “new”or"malloc",then usually you don’t need to worry about garabage.