Do classes memory manage themselves?

I’m fairly sure this is an obvious yes, but I want to clarify for myself how memory management works in UE- if I declare some generic data class, then declare a member somewhere:



UCLASS(BlueprintType)
class UMyDataClass : public UDataAsset {
	GENERATED_BODY()

};

UMyDataClass* newData = NewObject<UMyDataClass>();



Am I correct that newData will cease to exist the instant nobody is retaining a reference to it in memory? Or do I need to explicitly keep track of when I’m done with it, and manually wipe it from memory?

UClass’s and objects that inherit from UObject are garbage collected and don’t need manual memory management. :slight_smile:

It is advised though that if this object is temporary and not to be serialised then you need to specify to create it with in the ‘GetTransientPackage()’ or give it the object flag RF_Transient. This depends on how and what you use the newly created class for.

Hmm okay, thank you!! :slight_smile: