# Magical Garbage Collection gets invalid Array from ArrayPool and crashes

**URL:** <https://forums.unrealengine.com/t/magical-garbage-collection-gets-invalid-array-from-arraypool-and-crashes/379371>\
**Category:** Platform & Builds\
**Tags:** garbage-collector, serialization, garbage-collection, unreal-engine, question\
**Created:** [December 15, 2016, 2:47pm UTC](https://forums.unrealengine.com/t/magical-garbage-collection-gets-invalid-array-from-arraypool-and-crashes/379371 "2016-12-15T14:47:54Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![OgoxHammerschild](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@OgoxHammerschild](https://forums.unrealengine.com/u/OgoxHammerschild)\
**Post date:** [December 15, 2016, 2:47pm UTC](https://forums.unrealengine.com/t/magical-garbage-collection-gets-invalid-array-from-arraypool-and-crashes/379371/1 "2016-12-15T14:47:54Z")

</div>

Hi,

Unreal is hitting a break point at `FastReferenceCollector.h:290` but there is no error message and I dont know where to fix stuff. This is the snippet where it happens:

```
else if (ReferenceInfo.Type == GCRT_ArrayObject)
{
	// We're dealing with an array of object references.
	TArray<UObject*>& ObjectArray = *((TArray<UObject*>*)(StackEntryData + ReferenceInfo.Offset));
	TokenReturnCount = ReferenceInfo.ReturnCount;
	for (int32 ObjectIndex = 0, ObjectNum = ObjectArray.Num(); ObjectIndex < ObjectNum; ++ObjectIndex)
	{
		ReferenceProcessor.HandleTokenStreamObjectReference(NewObjectsToSerialize, CurrentObject, ObjectArray[ObjectIndex], ReferenceTokenStreamIndex, true);
	}
}

```

At `ReferenceProcessor.HandleTokenStreamObjectReference(...)` the break point is hit with `NewObjectsToSerialize` being `Invalid` . Sometimes the `Name` of `CurrentObject` is also `Invalid`, but not always.  
The `NewObjectsToSerialize` are coming from `*ArrayPool.GetArrayFromPool()` and `ArrayPool` is a `template` Type.

What I also noticed is that in the `else if` the `ReferenceInfo.Type` says it’s `8` while the `GCRT_ArrayObject` is `3`.

To me it looks like the GC is trying to clean something that isn’t there and then crashes. What is actually happening in this part of the GC?

---

<div class="post-metadata">

**Author:** ![Santor](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Santor](https://forums.unrealengine.com/u/Santor)\
**Post date:** [May 11, 2017, 9:00am UTC](https://forums.unrealengine.com/t/magical-garbage-collection-gets-invalid-array-from-arraypool-and-crashes/379371/2 "2017-05-11T09:00:28Z")

</div>

I have the same problem, OgoxHammerschild, did you find any solution?

---

<div class="post-metadata">

**Author:** ![OgoxHammerschild](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@OgoxHammerschild](https://forums.unrealengine.com/u/OgoxHammerschild)\
**Post date:** [May 14, 2017, 5:33pm UTC](https://forums.unrealengine.com/t/magical-garbage-collection-gets-invalid-array-from-arraypool-and-crashes/379371/3 "2017-05-14T17:33:12Z")

</div>

Hi Santor,

I didn’t find a solution for that, but in my case this error disappeared somehow over night with no concrete reason.

When I had the error I was thinking that it may have something to do with en-/disabling of actors, like you do in an object pool. Maybe Unreal GC thought “oh, you disabled this actor? you sure don’t need it anymore, right? let me take care of it”. but then enable the actor regardless, but it’s already gone…

It may also be that there is a single pointer to an actor and another pointer to the same actor inside an array and one of them was deleted but the other pointer still points to the deleted actor/object and just returns invalid rubbish.

But I can just guess… In the end, I don’t have a clue what is causing this error. Sorry ☹

---

<div class="post-metadata">

**Author:** ![sammichael25](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@sammichael25](https://forums.unrealengine.com/u/sammichael25)\
**Post date:** [January 20, 2023, 4:34am UTC](https://forums.unrealengine.com/t/magical-garbage-collection-gets-invalid-array-from-arraypool-and-crashes/379371/4 "2023-01-20T04:34:19Z")

</div>

I’m also getting this issue, did any of you find a solution or a way to debug it?

---

<div class="post-metadata">

**Author:** ![where44444](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@where44444](https://forums.unrealengine.com/u/where44444)\
**Post date:** [March 18, 2025, 5:56am UTC](https://forums.unrealengine.com/t/magical-garbage-collection-gets-invalid-array-from-arraypool-and-crashes/379371/5 "2025-03-18T05:56:37Z")

</div>

I had this same problem and found a bit of a long winded way to debug it, but it works.

1. I set the console variable gc.CollectGarbageEveryFrame 1 (that way it instantly crashes if the problem is there instead of waiting ~10-30 seconds)
2. I made a copy of my map
3. I deleted batches of similar actors until the problem went away
4. I found which actor it was, and then disabled and enabled bits of code to see what fixed and what caused the problem
5. It turned out to be a C++ struct that I recently changed, and it had a variable like this:

```auto
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = 1W4)
UObject* callback;

```

I tried adding a = nullptr so it looked like this:

```auto
UObject* callback = nullptr;

```

And that fixed it for me
