Garbage Collect UStructs()?

Dear Friends at Epic,

Thank you so much for UE4! Yay!

I am storing TArrays of UStructs().

New UStructs() are created locally inside a function called from DrawHUD and have no references to them after the function completes except the dynamic array they are stored in.

I periodically .Empty() the array and then refill it with new UStructs, and the old ones are no longer useful to my game.

Is there a way I can explicity delete the old UStructs() ?

Here’s my current UStruct definition:

USTRUCT()
struct FButtonStruct
{
	GENERATED_USTRUCT_BODY()

	//Vars
	int32 		type;
	int32		arrayIndex;
	float 		minX;
	float 		maxX;
	float 		minY;
	float 		maxY;
	
	//~~~~~~~~~~~~~~~~~~~
	
	//default properties
	
	FButtonStruct()
	{
		type = 255;
		arrayIndex = -1;
	}
};

Here’s my Dynamic Array:

TArray FileBrowserButtons;

Thanks!

Rama

It’s probably a good idea to initialize all members of your struct in the constructor. If you are adding them to the array by first allocating on the stack, for example, you will have bogus data in non-init’d members.

Thanks for the info James!

:slight_smile:

The garbage collection will occur automatically for structs with no references once removed from the dynamic array?

:slight_smile:

Rama

That is not an array of references to structs, it is an array of actual structs, so you don’t need to worry about GC. Our GC only collects UObjects though, you are responsible for managing non-UObject lifetimes yourself if you allocate them outside something like an array inside a UObject.

Thanks for the info James! :slight_smile: I’m having a lot of fun with UE4 c++, and I am making substantial progress with my project! :slight_smile: Thanks for your help!