TArray insertion invalidates contents

@nande, thanks for the reply.
At a certain point in time t, a actor enters a collision box. OnOverlapBegin triggers then OnOverlapEnd triggers.

Here is some more code:

	UPROPERTY(VisibleAnywhere)
		TArray<UOObject*> arr;

	UPROPERTY()
		uint64 foo_section;
void AAObject::BeginPlay()
		{

                       uint8 section = calculated_section();
			if (section == 1) 
			{

				foo->obj_index = section;
				foo->previous_oobject_index = foo->obj_index;
				foo->foo_index = arr[section]->foos.Num();
				foo->previous_foo_index = foo->foo_index;
				arr[section]->foos.Insert(foo, foo->foo_index);
				arr[section]->number_of_foos++;
				arr[section]->index = section;
				
			}
			//...
			//...
			//...
			
		}
		
		void AAObject::OnOverlapBegin(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
		{
			
			Afoo* foo = Cast<Afoo>(OtherActor);
			UOoobject* oobject = Cast<UOoobject>(OverlappedComp);
			
			foo_section = oobject->index;
			foo->obj_index = oobject->index;
			foo->foo_index = arr[foo->obj_index]->foos.Num();
			
			if (arr[foo->obj_index]->foos.IsValidIndex(foo->foo_index))
			{
				if (arr[foo->obj_index]->foos[foo->foo_index] == nullptr)
					arr[foo->obj_index]->foos[foo->foo_index] = foo;
			
			
			}
			else
				arr[foo->obj_index]->foos.Insert(foo, foo->foo_index);


			arr[foo->obj_index]->number_of_foos++;
			
			
		}
		
	void AAObject::OnOverlapEnd(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex) 
	{

	Afoo* foo = Cast<Afoo>(OtherActor);
	UOoobject* oobject = Cast<UOoobject>(OverlappedComp);

	if (OtherActor->IsA(Afoo::StaticClass())) 
	{

		foo->previous_oobject_index = oobject->index;
		if (arr[oobject->index]->foos.Num() == 0)
			return;
		else 
		{

			arr[oobject->index]->number_of_foos--;
			
			if (IsValid(arr[oobject->index]->foos[foo->previous_foo_index]))
			{

				arr[oobject->index]->foos[foo->previous_foo_index] = nullptr;
			
				foo->previous_oobject_index = foo->obj_index;
				foo->previous_foo_index = foo->foo_index;

			}
			else 
			{
				// This executes because [0] and [1] are now NULL

				GEngine->AddOnScreenDebugMessage(-1, 15.f, FColor::Red, TEXT("[oobject ending] foo is not valid"));
				return;

			}

		}

	}

  }