Hi guys,
my latest project includes a big array of FVectors with boolean value. I got lost in the UObject and Garbage collector though. I have created an UStruct FCubeP (CubePoint)
USTRUCT()
struct FCubeP
{
GENERATED_USTRUCT_BODY()
UPROPERTY()
bool isActive;
UPROPERTY()
FVector location;
//base constructor
FCubeP()
{
}
};
Then in my Actor I am creating dummy array of many points and then in BeginDestroy() I try to mark it for GC to get it. Aka, setting each pointer to nullptr. I have read that this should be the proper way to mark UStruct for GC.
ALeakTestActor::ALeakTestActor()
{
PrimaryActorTick.bCanEverTick = false;
// IN HEADER FILE : TArray<FCubeP *> list;
FCubeP * tempPoint = new FCubeP();
list.Add(tempPoint);
for (int32 b = 0; b < 99999999; b++) {
list.Add(new FCubeP());
}
}
void ALeakTestActor::BeginDestroy()
{
for (int32 b = 0; b < list.Num(); b++) {
list[b] = nullptr;
}
}
But it crashes or still leaves memory allocated. Can anyone please help me how to store large number of pointers to my own object and dispose it correctly? I know I can do it manually (pure c++) but I am trying to learn the Garbage collector way.
Kind regards,
Crispy