Crash related to Garbage Collection occurring

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?

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)

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++

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++

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.

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.

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)

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