# Classes never garbage collected?

**URL:** <https://forums.unrealengine.com/t/classes-never-garbage-collected/1720618>\
**Category:** Issues and Bug Reporting\
**Tags:** fortnite-creative, unreal-editor-for-fortnite, fortnite\
**Created:** [February 29, 2024, 4:08pm UTC](https://forums.unrealengine.com/t/classes-never-garbage-collected/1720618 "2024-02-29T16:08:52Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![im\_a\_lama](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/im_a_lama/32/995063_2.png) [@im\_a\_lama](https://forums.unrealengine.com/u/im_a_lama)\
**Post date:** [February 29, 2024, 4:08pm UTC](https://forums.unrealengine.com/t/classes-never-garbage-collected/1720618/1 "2024-02-29T16:08:52Z")

</div>

### Please select what you are reporting on:

Verse

### What Type of Bug are you experiencing?

Memory

### Summary

Probably related to [Weak maps don't hold weak references??](https://forums.unrealengine.com/t/weak-maps-dont-hold-weak-references/1720472)

Garbage collector seem to (never?) collect unused classes

Go to the !!! ISSUE !!! line in code

### Steps to Reproduce

```auto
using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }

some_class := class:
    MemoryIntensiveArrays : [][]float

test_garbage_collector := class(creative_device):

    OnBegin<override>()<suspends>:void=
        # Don't use for or loops just in case they mess up the GC
        # Should crash around the 30th call
        spawn{FillMemory()}
        Sleep(1.0)
        spawn{FillMemory()}
        Sleep(1.0)
        spawn{FillMemory()}
        Sleep(1.0)
        spawn{FillMemory()}
        Sleep(1.0)
        spawn{FillMemory()}
        Sleep(1.0)
        spawn{FillMemory()}
        Sleep(1.0)
        spawn{FillMemory()}
        Sleep(1.0)
        spawn{FillMemory()}
        Sleep(1.0)
        spawn{FillMemory()}
        Sleep(1.0)
        spawn{FillMemory()}
        Sleep(1.0)
        spawn{FillMemory()}
        Sleep(1.0)
        spawn{FillMemory()}
        Sleep(1.0)
        spawn{FillMemory()}
        Sleep(1.0)
        spawn{FillMemory()}
        Sleep(1.0)
        spawn{FillMemory()}
        Sleep(1.0)
        spawn{FillMemory()}
        Sleep(1.0)
        spawn{FillMemory()}
        Sleep(1.0)
        spawn{FillMemory()}
        Sleep(1.0)
        spawn{FillMemory()}
        Sleep(1.0)
        spawn{FillMemory()}
        Sleep(1.0)
        spawn{FillMemory()}
        Sleep(1.0)
        spawn{FillMemory()}
        Sleep(1.0)
        spawn{FillMemory()}
        Sleep(1.0)
        spawn{FillMemory()}
        Sleep(1.0)
        spawn{FillMemory()}
        Sleep(1.0)
        spawn{FillMemory()}
        Sleep(1.0)
        spawn{FillMemory()}
        Sleep(1.0)
        spawn{FillMemory()}
        Sleep(1.0)
        spawn{FillMemory()}
        Sleep(1.0)
        spawn{FillMemory()}
        Sleep(1.0)
        spawn{FillMemory()}
        Sleep(1.0)
        spawn{FillMemory()}
        Sleep(1.0)
        spawn{FillMemory()}
        Sleep(1.0)
        spawn{FillMemory()}
        Sleep(1.0)
        spawn{FillMemory()}
        Sleep(1.0)
        spawn{FillMemory()}
        Sleep(1.0)
        spawn{FillMemory()}
        Sleep(1.0)
        spawn{FillMemory()}
        Sleep(1.0)
        spawn{FillMemory()}
        Sleep(1.0)
        spawn{FillMemory()}
        Sleep(1.0)
        spawn{FillMemory()}
        Sleep(1.0)
        spawn{FillMemory()}
        Sleep(1.0)
        spawn{FillMemory()}
        Sleep(1.0)
        spawn{FillMemory()}
        Sleep(1.0)
        spawn{FillMemory()}
        Sleep(1.0)
        spawn{FillMemory()}
        Sleep(1.0)
        spawn{FillMemory()}
        Sleep(1.0)
        Print("Didn't crash")

    # Creates huge arrays but never store them anywhere (so they should be collected by the GC)
    # Do it in a separate function in case GC only acts after leaving function scope
    # <suspends> and spawned just in case GC would be waiting for OnBegin to end
    FillMemory()<suspends>:void=
        Print("Making big array")
        HugeFloatArray := for(__ := 0..1000000) {0.123456789} # Create the big array again in case it would've been passed by reference somehow
        
        # !!!!!!!!!!!!!!!!!!!!!!!!
        # !!!!!!!! ISSUE !!!!!!!!!
        # !!!!!!!!!!!!!!!!!!!!!!!!
        # Commenting the line right under make GC work again
        some_class: # <-- Don't store anywhere, still not collected by GC
            MemoryIntensiveArrays := array:
                HugeFloatArray
                HugeFloatArray
                HugeFloatArray
                HugeFloatArray
                HugeFloatArray
                HugeFloatArray
                HugeFloatArray
                HugeFloatArray
                HugeFloatArray
                HugeFloatArray
                HugeFloatArray
                HugeFloatArray
                HugeFloatArray
                HugeFloatArray
                HugeFloatArray
                HugeFloatArray
                HugeFloatArray
                HugeFloatArray
                HugeFloatArray
                HugeFloatArray
                HugeFloatArray
                HugeFloatArray
                HugeFloatArray
                HugeFloatArray
                HugeFloatArray
                HugeFloatArray
                HugeFloatArray
                HugeFloatArray
                HugeFloatArray
                HugeFloatArray
                HugeFloatArray
                HugeFloatArray
                HugeFloatArray
                HugeFloatArray
                HugeFloatArray
                HugeFloatArray
                HugeFloatArray
                HugeFloatArray
                HugeFloatArray
                HugeFloatArray
                HugeFloatArray
                HugeFloatArray
                HugeFloatArray
                HugeFloatArray
                HugeFloatArray
                HugeFloatArray
                HugeFloatArray
                HugeFloatArray
                HugeFloatArray
                HugeFloatArray
                HugeFloatArray
                HugeFloatArray
                HugeFloatArray
                HugeFloatArray
                HugeFloatArray
                HugeFloatArray
                HugeFloatArray
                HugeFloatArray
                HugeFloatArray
                HugeFloatArray
                HugeFloatArray
                HugeFloatArray
                HugeFloatArray
                HugeFloatArray
                HugeFloatArray
                HugeFloatArray
                HugeFloatArray
                HugeFloatArray
                HugeFloatArray
                HugeFloatArray
                HugeFloatArray
                HugeFloatArray
                HugeFloatArray
                HugeFloatArray
                HugeFloatArray
                HugeFloatArray
                HugeFloatArray
                HugeFloatArray
                HugeFloatArray
                HugeFloatArray
                HugeFloatArray
                HugeFloatArray
                HugeFloatArray
                HugeFloatArray
                HugeFloatArray
                HugeFloatArray
                HugeFloatArray
                HugeFloatArray
                HugeFloatArray
                HugeFloatArray
                HugeFloatArray
                HugeFloatArray
                HugeFloatArray
                HugeFloatArray
                HugeFloatArray
                HugeFloatArray
                HugeFloatArray
                HugeFloatArray
                HugeFloatArray
                HugeFloatArray

        return # In case the object is returned instead as it is the last statement

```

### Expected Result

Memory should be freed up if the class is not referenced anywhere (the same way the native array do)

### Observed Result

GC seem to only collect the native array, when embed in a class it’s not collected

### Platform(s)

PC

---

<div class="post-metadata">

**Author:** ![Bug-Reporter](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/bug-reporter/32/1223650_2.png) [@Bug-Reporter](https://forums.unrealengine.com/u/Bug-Reporter)\
**Post date:** [February 29, 2024, 4:17pm UTC](https://forums.unrealengine.com/t/classes-never-garbage-collected/1720618/2 "2024-02-29T16:17:32Z")

</div>

The status of UCB-1310 incident has been moved from ‘Awaiting Validation’ to ‘Needs Triage’.

---

<div class="post-metadata">

**Author:** ![im\_a\_lama](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/im_a_lama/32/995063_2.png) [@im\_a\_lama](https://forums.unrealengine.com/u/im_a_lama)\
**Post date:** [March 29, 2024, 8:29am UTC](https://forums.unrealengine.com/t/classes-never-garbage-collected/1720618/3 "2024-03-29T08:29:09Z")

</div>

Any news on this ?

---

<div class="post-metadata">

**Author:** ![im\_a\_lama](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/im_a_lama/32/995063_2.png) [@im\_a\_lama](https://forums.unrealengine.com/u/im_a_lama)\
**Post date:** [April 4, 2024, 9:16pm UTC](https://forums.unrealengine.com/t/classes-never-garbage-collected/1720618/4 "2024-04-04T21:16:39Z")

</div>

Bump? 👀

---

<div class="post-metadata">

**Author:** ![OohWowow](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/oohwowow/32/1003445_2.png) [@OohWowow](https://forums.unrealengine.com/u/OohWowow)\
**Post date:** [July 19, 2024, 4:08pm UTC](https://forums.unrealengine.com/t/classes-never-garbage-collected/1720618/5 "2024-07-19T16:08:03Z")

</div>

any update here?

---

<div class="post-metadata">

**Author:** ![im\_a\_lama](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/im_a_lama/32/995063_2.png) [@im\_a\_lama](https://forums.unrealengine.com/u/im_a_lama)\
**Post date:** [October 22, 2024, 6:30am UTC](https://forums.unrealengine.com/t/classes-never-garbage-collected/1720618/6 "2024-10-22T06:30:38Z")

</div>

Bump, still needs triage ?

---

<div class="post-metadata">

**Author:** ![OohWowow](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/oohwowow/32/1003445_2.png) [@OohWowow](https://forums.unrealengine.com/u/OohWowow)\
**Post date:** [November 2, 2024, 4:51am UTC](https://forums.unrealengine.com/t/classes-never-garbage-collected/1720618/7 "2024-11-02T04:51:38Z")

</div>

im with you LAMA

---

<div class="post-metadata">

**Author:** ![aveldev](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@aveldev](https://forums.unrealengine.com/u/aveldev)\
**Post date:** [December 16, 2024, 4:17pm UTC](https://forums.unrealengine.com/t/classes-never-garbage-collected/1720618/8 "2024-12-16T16:17:57Z")

</div>

update please ☹

---

<div class="post-metadata">

**Author:** ![im\_a\_lama](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/im_a_lama/32/995063_2.png) [@im\_a\_lama](https://forums.unrealengine.com/u/im_a_lama)\
**Post date:** [December 16, 2024, 5:16pm UTC](https://forums.unrealengine.com/t/classes-never-garbage-collected/1720618/9 "2024-12-16T17:16:47Z")

</div>

I can confirm this is still happening, some clarifications could be great 👀

---

<div class="post-metadata">

**Author:** ![Flak](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/flak/32/769441_2.png) [@Flak](https://forums.unrealengine.com/u/Flak)\
**Post date:** [December 16, 2024, 5:19pm UTC](https://forums.unrealengine.com/t/classes-never-garbage-collected/1720618/10 "2024-12-16T17:19:38Z")

</div>

> [@Bug-Reporter](#):
>
> UCB-1310

This was closed as fixed, I’ll check into it.

---

<div class="post-metadata">

**Author:** ![Flak](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/flak/32/769441_2.png) [@Flak](https://forums.unrealengine.com/u/Flak)\
**Post date:** [December 16, 2024, 5:57pm UTC](https://forums.unrealengine.com/t/classes-never-garbage-collected/1720618/11 "2024-12-16T17:57:59Z")

</div>

They are reopening and checking into it. Thanks for the ping!

---

<div class="post-metadata">

**Author:** ![AlexanderW\_LEGO](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@AlexanderW\_LEGO](https://forums.unrealengine.com/u/AlexanderW_LEGO)\
**Post date:** [January 20, 2025, 3:55pm UTC](https://forums.unrealengine.com/t/classes-never-garbage-collected/1720618/12 "2025-01-20T15:55:50Z")

</div>

Hey all, we’ve encountered this issue as well after removing references to a large number of custom class instances over time.  
It seems to be causing memory reached critical levels errors on Switch as well which is pretty problematic.

---

<div class="post-metadata">

**Author:** ![aveldev](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@aveldev](https://forums.unrealengine.com/u/aveldev)\
**Post date:** [January 28, 2025, 12:18am UTC](https://forums.unrealengine.com/t/classes-never-garbage-collected/1720618/13 "2025-01-28T00:18:16Z")

</div>

Hi @Flak , any update?

---

<div class="post-metadata">

**Author:** ![Flak](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/flak/32/769441_2.png) [@Flak](https://forums.unrealengine.com/u/Flak)\
**Post date:** [January 28, 2025, 2:27pm UTC](https://forums.unrealengine.com/t/classes-never-garbage-collected/1720618/14 "2025-01-28T14:27:17Z")

</div>

Checking!

---

<div class="post-metadata">

**Author:** ![Flak](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/flak/32/769441_2.png) [@Flak](https://forums.unrealengine.com/u/Flak)\
**Post date:** [January 29, 2025, 11:36am UTC](https://forums.unrealengine.com/t/classes-never-garbage-collected/1720618/15 "2025-01-29T11:36:08Z")

</div>

Nothing yet, I’ll let you know if I need more information.

---

<div class="post-metadata">

**Author:** ![Flak](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/flak/32/769441_2.png) [@Flak](https://forums.unrealengine.com/u/Flak)\
**Post date:** [January 30, 2025, 12:51pm UTC](https://forums.unrealengine.com/t/classes-never-garbage-collected/1720618/16 "2025-01-30T12:51:43Z")

</div>

@im_a_lama could we get your project files?

---

<div class="post-metadata">

**Author:** ![im\_a\_lama](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/im_a_lama/32/995063_2.png) [@im\_a\_lama](https://forums.unrealengine.com/u/im_a_lama)\
**Post date:** [January 30, 2025, 7:07pm UTC](https://forums.unrealengine.com/t/classes-never-garbage-collected/1720618/17 "2025-01-30T19:07:28Z")

</div>

Uhm, they just need to copy paste the repro lol 👐

I know coz I had to retry to repro on another project the other day

---

<div class="post-metadata">

**Author:** ![im\_a\_lama](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/im_a_lama/32/995063_2.png) [@im\_a\_lama](https://forums.unrealengine.com/u/im_a_lama)\
**Post date:** [February 26, 2025, 9:03pm UTC](https://forums.unrealengine.com/t/classes-never-garbage-collected/1720618/18 "2025-02-26T21:03:41Z")

</div>

Any news regarding this issue ?

---

<div class="post-metadata">

**Author:** ![VysenaWoyka](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/vysenawoyka/32/1003669_2.png) [@VysenaWoyka](https://forums.unrealengine.com/u/VysenaWoyka)\
**Post date:** [March 7, 2025, 12:31am UTC](https://forums.unrealengine.com/t/classes-never-garbage-collected/1720618/19 "2025-03-07T00:31:31Z")

</div>

> [@im\_a\_lama](#):
>
> `FillMemory`

I can confirm this is still an issue that can HIGHLY impact performances

---

<div class="post-metadata">

**Author:** ![TaiKoo](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/taikoo/32/1005499_2.png) [@TaiKoo](https://forums.unrealengine.com/u/TaiKoo)\
**Post date:** [March 7, 2025, 1:12am UTC](https://forums.unrealengine.com/t/classes-never-garbage-collected/1720618/20 "2025-03-07T01:12:06Z")

</div>

I can confirm that this is a real problem, for example here I’m creating a material instance in verse, i have the impression that it doesn’t fade over time.

```auto
using { /Fortnite.com/Devices }
using { /UnrealEngine.com/Temporary/Diagnostics }
using { /Verse.org/Colors }
using { /Verse.org/Random }
using { /Verse.org/Simulation }
using { /UnrealEngine.com/Temporary/SpatialMath }

hello_world_device := class(creative_device):
    @editable Spawn : int = 25
    @editable Size : float = 50.0

    OnBegin<override>()<suspends>:void=
        for(X := 0..Int[Spawn * 1.0 / 2.0]):
            for(Y := 0..Int[Spawn * 1.0 / 2.0]):
                if(Prop := SpawnProp(DefaultCreativePropAsset, transform{Scale:=vector3{X:=Size,Y:=Size,Z:=Size},Translation:=vector3{X:=Size + (Size * X),Y:=Size + (Size * Y)} - vector3{X:=Size*Spawn / 4.0,Y:=Size*Spawn / 4.0} })(0)?):
                    Prop.SetMesh(Meshes.Box_93BD354E)
                    spawn{Init(Prop)}

    Init(CreativeProp:creative_prop)<suspends>:void=
        loop:
            CreativeProp.SetMaterial(M_ColorMaster_material{BaseColor:=color{R:=GetRandomFloat(0.0,1.0),G:=GetRandomFloat(0.0,1.0),B:=GetRandomFloat(0.0,1.0)}})
            Sleep(0.25)

```

[Next page](https://forums.unrealengine.com/t/classes-never-garbage-collected/1720618.md?page=2)
