Should I free the memory of a SaveGame pointer?

I have this pointer that I got using the function.

USaveGame* saveGame = UGameplayStatics::LoadGameFromMemory(Content);

I’m looking at the documentation and it doesn’t say anything about freeing the memory.

Is this pointer managed by the garbage collector?

Or should I free the memory by myself?

And in the second case, what should I use to do it? free(), delete… Or is there a function in the API specifically designed to free UObjects?

Thank you so much!!

If I’m not mistaken, all UObject classes are uses garbage collector, which handles memory free if variable out of scope, so, you don’t need to manually free memory.
You can read about UE garbage collector here: link to documentation.

1 Like

mnelenpridumivat is not mistaken indeed. You can see that the save game is of the type USaveGame. All Unreal classes that extend UObject have a U in front of their name, and all of those are garbage collected automatically when nothing references them anymore.

In short, don’t free it yourself, Unreal will handle it for you.

1 Like

thank you very much for your help

thank you very much for your help too!!