Classes never garbage collected?

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

Garbage collector seem to (never?) collect unused classes

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

Steps to Reproduce

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

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

1 Like

Any news on this ?

Bump? :eyes: