# Deleting TArray of pointers

**URL:** <https://forums.unrealengine.com/t/deleting-tarray-of-pointers/348912>\
**Category:** Getting Started & Setup\
**Tags:** leak, crashes, unreal-engine, Array, memory, pointer, question\
**Created:** [February 27, 2016, 11:32pm UTC](https://forums.unrealengine.com/t/deleting-tarray-of-pointers/348912 "2016-02-27T23:32:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Crispy\_Penguin](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Crispy\_Penguin](https://forums.unrealengine.com/u/Crispy_Penguin)\
**Post date:** [February 27, 2016, 11:32pm UTC](https://forums.unrealengine.com/t/deleting-tarray-of-pointers/348912/1 "2016-02-27T23:32:40Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![phoboz](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@phoboz](https://forums.unrealengine.com/u/phoboz)\
**Post date:** [February 28, 2016, 3:59am UTC](https://forums.unrealengine.com/t/deleting-tarray-of-pointers/348912/2 "2016-02-28T03:59:26Z")

</div>

Could you post the log?

---

<div class="post-metadata">

**Author:** ![limpit666](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@limpit666](https://forums.unrealengine.com/u/limpit666)\
**Post date:** [October 15, 2016, 4:44pm UTC](https://forums.unrealengine.com/t/deleting-tarray-of-pointers/348912/3 "2016-10-15T16:44:00Z")

</div>

Sorry for bumping this but I would love an answer to this too.

I have a TArray that holds pointers to a custom data class I created to index some instanced tiles. Deleting some pointers at runtime is good, but when I want to delete the pointer array when the window is closed on EndPlay(), Unreal crashes. Is there a proper way to do this?

I get:

```
Access violation - code c0000005 (first/second chance not available)

UE4Editor_Core!rml::internal::Block::findObjectSize()
UE4Editor_Core!FMallocTBB::Free() [d:\build\++ue4+release-4.13+compile\sync\engine\source\runtime\core\private\hal\malloctbb.cpp:109]
UE4Editor_Core!FMemory::Free() [d:\build\++ue4+release-4.13+compile\sync\engine\source\runtime\core\public\hal\fmemory.inl:49]
UE4Editor_Athena_5349!AMap_Controller::EndPlay() [c:\users\omarf\desktop\athena\source\athena\maps\map_controller.cpp:76]

```

Thanks for the help.
