# Crash related to Garbage Collection occurring

**URL:** <https://forums.unrealengine.com/t/crash-related-to-garbage-collection-occurring/442920>\
**Category:** Getting Started & Setup\
**Tags:** Destroy-Actor, garbage-collection, unreal-engine, crash, editor, question\
**Created:** [February 7, 2019, 5:08pm UTC](https://forums.unrealengine.com/t/crash-related-to-garbage-collection-occurring/442920 "2019-02-07T17:08:58Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![anon11580166](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anon11580166](https://forums.unrealengine.com/u/anon11580166)\
**Post date:** [February 7, 2019, 5:08pm UTC](https://forums.unrealengine.com/t/crash-related-to-garbage-collection-occurring/442920/1 "2019-02-07T17:08:58Z")

</div>

So my team has this problem with a crash that occurs periodically on all platforms, which seems to reference garbage collection, but we’re unsure how to correct it. The assert shown below is thrown while the program is calls FMemory::Trim() from inside CollectGarbageInternal().

```
Assertion failed: !NumFree.GetValue() [File:C:\p4\Repo\Engine\Source\Runtime\Core\Public\Containers/LockFreeFixedSizeAllocator.h] [Line: 245]

```

It might be related to the ensure that we fail when we stop the editor from playing a scene. It only happens the first time the scene is run in editor, and after that it doesn’t happen anymore:

```
Ensure condition failed: !IsGarbageCollecting() [File:C:\p4\Repo\Engine\Source\Runtime\UMG\Private\Slate\SObjectWidget.cpp] [Line: 41] 
SObjectWidget for 'BPW_Button_Item_C /Engine/Transient.UnrealEdEngine_0:GameInstance_0.BPH_HudInv_C_0.WidgetTree_0.BPW_Button_Item_0' destroyed while collecting garbage. This can lead to multiple GCs being required to cleanup the object. Possible causes might be,
1) ReleaseSlateResources not being implemented for the owner of this pointer.
2) You may just be holding onto some slate pointers on an actor that don't get reset until the actor is Garbage Collected. You should avoid doing this, and instead reset those references when the actor is Destroyed.
[2019.02.07-15.36.27:763][558]LogOutputDevice: Error: Ensure condition failed: !IsGarbageCollecting() [File:C:\p4\Repo\Engine\Source\Runtime\UMG\Private\Slate\SObjectWidget.cpp] [Line: 41] 
SObjectWidget for 'BPW_Button_Item_C /Engine/Transient.UnrealEdEngine_0:GameInstance_0.BPH_HudInv_C_0.WidgetTree_0.BPW_Button_Item_0' destroyed while collecting garbage. This can lead to multiple GCs being required to cleanup the object. Possible causes might be,
1) ReleaseSlateResources not being implemented for the owner of this pointer.
2) You may just be holding onto some slate pointers on an actor that don't get reset until the actor is Garbage Collected. You should avoid doing this, and instead reset those references when the actor is Destroyed.

```

We’re running with a clean engine source, so I would assume the above is related, but I’m unsure what changes need to be made to our HUD to stop this from occurring, since its mostly implemented in Blueprint. Any ideas?

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_8e19b3a9](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_8e19b3a9](https://forums.unrealengine.com/u/anonymous_user_8e19b3a9)\
**Post date:** [March 18, 2019, 3:05am UTC](https://forums.unrealengine.com/t/crash-related-to-garbage-collection-occurring/442920/2 "2019-03-18T03:05:20Z")

</div>

I have encountered the same issue in UE4.21.2.  
I saw NumFree.GetValue() is 6 in the debugger.  
The log said no GCed object at last time.

logs

```
LogGarbage: Collecting garbage (GCheckForIllegalMarkPendingKill = 1)
LogGarbage: 4.163901 ms for Verify GC Assumptions
LogGarbage: 14.580565 ms for GC
LogGarbage: 0.429370 ms for Gather Unreachable Objects (0 objects collected including 0 cluster objects from 0 clusters)

```

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_8e19b3a9](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_8e19b3a9](https://forums.unrealengine.com/u/anonymous_user_8e19b3a9)\
**Post date:** [March 18, 2019, 12:50pm UTC](https://forums.unrealengine.com/t/crash-related-to-garbage-collection-occurring/442920/3 "2019-03-18T12:50:14Z")

</div>

callstack

```
KERNELBASE.dll!00007ffbd1d1a388()	Unknown
MyGame.exe!FWindowsErrorOutputDevice::Serialize(const wchar_t * Msg, ELogVerbosity::Type Verbosity, const FName & Category) Line 63	C++
MyGame.exe!FOutputDevice::LogfImpl(const wchar_t * Fmt, ...) Line 71	C++
[Inline Frame] MyGame.exe!FOutputDevice::Logf(const wchar_t[47] &) Line 227	C++
MyGame.exe!FDebug::AssertFailed(const char * Expr, const char * File, int Line, const wchar_t * Format, ...) Line 417	C++
MyGame.exe!TLockFreeFixedSizeAllocator<65536,128,FThreadSafeCounter>::Trim() Line 246	C++
[Inline Frame] MyGame.exe!FPageAllocator::LatchProtectedMode::__l2::<lambda_ff677f21f724bafdda1618320d90e6c1>::operator()() Line 246	C++
[Inline Frame] MyGame.exe!UE4Tuple_Private::TTupleImpl<TIntegerSequence<unsigned int> >::ApplyAfter(FPageAllocator::LatchProtectedMode::__l2::<lambda_ff677f21f724bafdda1618320d90e6c1> &) Line 498	C++
[Inline Frame] MyGame.exe!TBaseFunctorDelegateInstance<TTypeWrapper<void> __cdecl(void),<lambda_ff677f21f724bafdda1618320d90e6c1> >::Execute() Line 893	C++
MyGame.exe!TBaseFunctorDelegateInstance<void __cdecl(void),<lambda_ff677f21f724bafdda1618320d90e6c1> >::ExecuteIfSafe() Line 956	C++
MyGame.exe!TBaseMulticastDelegate<void>::Broadcast() Line 974	C++
MyGame.exe!FMemory::Trim() Line 517	C++
MyGame.exe!CollectGarbageInternal(EObjectFlags KeepFlags, bool bPerformFullPurge) Line 1606	C++
MyGame.exe!TryCollectGarbage(EObjectFlags KeepFlags, bool bPerformFullPurge) Line 1700	C++
[Inline Frame] MyGame.exe!UEngine::PerformGarbageCollectionAndCleanupActors() Line 1323	C++
MyGame.exe!UEngine::ConditionalCollectGarbage() Line 1297	C++
MyGame.exe!UWorld::Tick(ELevelTick TickType, float DeltaSeconds) Line 1647	C++

```

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_8e19b3a9](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_8e19b3a9](https://forums.unrealengine.com/u/anonymous_user_8e19b3a9)\
**Post date:** [March 18, 2019, 12:52pm UTC](https://forums.unrealengine.com/t/crash-related-to-garbage-collection-occurring/442920/4 "2019-03-18T12:52:49Z")

</div>

callstack

```
KERNELBASE.dll!00007ffbd1d1a388()	Unknown
MyGame.exe!FWindowsErrorOutputDevice::Serialize(const wchar_t * Msg, ELogVerbosity::Type Verbosity, const FName & Category) Line 63	C++
MyGame.exe!FOutputDevice::LogfImpl(const wchar_t * Fmt, ...) Line 71	C++
[Inline Frame] MyGame.exe!FOutputDevice::Logf(const wchar_t[47] &) Line 227	C++
MyGame.exe!FDebug::AssertFailed(const char * Expr, const char * File, int Line, const wchar_t * Format, ...) Line 417	C++
MyGame.exe!TLockFreeFixedSizeAllocator<65536,128,FThreadSafeCounter>::Trim() Line 246	C++
[Inline Frame] MyGame.exe!FPageAllocator::LatchProtectedMode::__l2::<lambda_ff677f21f724bafdda1618320d90e6c1>::operator()() Line 246	C++
[Inline Frame] MyGame.exe!UE4Tuple_Private::TTupleImpl<TIntegerSequence<unsigned int> >::ApplyAfter(FPageAllocator::LatchProtectedMode::__l2::<lambda_ff677f21f724bafdda1618320d90e6c1> &) Line 498	C++
[Inline Frame] MyGame.exe!TBaseFunctorDelegateInstance<TTypeWrapper<void> __cdecl(void),<lambda_ff677f21f724bafdda1618320d90e6c1> >::Execute() Line 893	C++
MyGame.exe!TBaseFunctorDelegateInstance<void __cdecl(void),<lambda_ff677f21f724bafdda1618320d90e6c1> >::ExecuteIfSafe() Line 956	C++
MyGame.exe!TBaseMulticastDelegate<void>::Broadcast() Line 974	C++
MyGame.exe!FMemory::Trim() Line 517	C++
MyGame.exe!CollectGarbageInternal(EObjectFlags KeepFlags, bool bPerformFullPurge) Line 1606	C++
MyGame.exe!TryCollectGarbage(EObjectFlags KeepFlags, bool bPerformFullPurge) Line 1700	C++
[Inline Frame] MyGame.exe!UEngine::PerformGarbageCollectionAndCleanupActors() Line 1323	C++
MyGame.exe!UEngine::ConditionalCollectGarbage() Line 1297	C++
MyGame.exe!UWorld::Tick(ELevelTick TickType, float DeltaSeconds) Line 1647	C++

```

---

<div class="post-metadata">

**Author:** ![Shmoopy1701](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/shmoopy1701/32/1194536_2.png) [@Shmoopy1701](https://forums.unrealengine.com/u/Shmoopy1701)\
**Post date:** [April 29, 2019, 4:48pm UTC](https://forums.unrealengine.com/t/crash-related-to-garbage-collection-occurring/442920/5 "2019-04-29T16:48:20Z")

</div>

Recurring problem we think is related to particle system garbage collection crashing not being 100% fixed.

No known workaround AFAIK aside from upgrading to next engine version and hope they fixed it.

---

<div class="post-metadata">

**Author:** ![siditious](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@siditious](https://forums.unrealengine.com/u/siditious)\
**Post date:** [May 9, 2019, 5:20am UTC](https://forums.unrealengine.com/t/crash-related-to-garbage-collection-occurring/442920/6 "2019-05-09T05:20:48Z")

</div>

I’m currently experiencing the same issue. It seems to happen when I get a certain number of objects in garbage collection at the same time.

---

<div class="post-metadata">

**Author:** ![Rashura](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Rashura](https://forums.unrealengine.com/u/Rashura)\
**Post date:** [May 29, 2019, 11:40am UTC](https://forums.unrealengine.com/t/crash-related-to-garbage-collection-occurring/442920/7 "2019-05-29T11:40:16Z")

</div>

I also came across this issue and for us it was a missing call to the overridden parent function in the widget blueprint/code ( Super::Endplay or Super::Destruct)

---

<div class="post-metadata">

**Author:** ![RafaCP](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@RafaCP](https://forums.unrealengine.com/u/RafaCP)\
**Post date:** [November 10, 2020, 11:11pm UTC](https://forums.unrealengine.com/t/crash-related-to-garbage-collection-occurring/442920/8 "2020-11-10T23:11:24Z")

</div>

Still getting similar Exception Thrown when stopping the project while running in the Editor. I’m using UE4.25.3 - Oculus source version.
