Weak maps not really holding weak references

Summary

This could either be a weak_map issue or a garbage collector issue

c.f. Weak maps don't hold weak references??
c.f. Classes never garbage collected?

Please select what you are reporting on:

Verse

What Type of Bug are you experiencing?

Stability

Steps to Reproduce

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

unique_object := class<unique>:
    MemoryIntensiveArrays : [][]float

test_weak_maps := class(creative_device):

    var SomeWeakMap : weak_map(unique_object, logic) = map{}
    # var SomeWeakMap : [unique_object]logic = map{}

    OnBegin<override>()<suspends>:void=
        HugeFloatArray := for(__ := 0..1000000) {0.123456789} # Should be passed by copy as every array do
        for(I := 1..10000):
            NewObject := unique_object:
                MemoryIntensiveArrays := array:
                    HugeFloatArray
                    HugeFloatArray
                    HugeFloatArray
                    HugeFloatArray
                    HugeFloatArray
                    HugeFloatArray
                    HugeFloatArray
                    HugeFloatArray
                    HugeFloatArray
                    HugeFloatArray

            option{set SomeWeakMap[NewObject] = true}

            Print("Itration({I})")
            Sleep(0.0)
            # NewObject should be removed by garbage collector here?

Expected Result

Server shouldn’t crash (see repro)

Observed Result

Server crashes (see repro)

Platform(s)

PC

@rhyan.smith Thanks for the answer, here’s the post. Make sure to look at the other post as it seems like there have been assigned tickets to it that got opened and closed and I’m not sure the GC problem got solved

1 Like

FORT-1148386 has been created and its status is ‘Unconfirmed’. This is now in a queue to be reproduced and confirmed.

Thank you, Lama!

1 Like

Here’s a repro that tries to prove class scoped weak_map(player) have the same problem. (connect a 2nd player once, make them leave, come back minutes later, crash)

unique_object := class<unique>:
    MemoryIntensiveArrays : [][]float

test_array_map := class(creative_device):

    var SomeWeakMap : weak_map(player, []unique_object) = map{}
    # var SomeWeakMap : [unique_object]logic = map{}

    HugeFloatArray : []float = for(__ := 0..1000000) {0.123456789} # Should be passed by copy as every array do

    OnBegin<override>()<suspends>:void=
        loop:
            Player := GetPlayspace().PlayerAddedEvent().Await()

            for(I := 1..250):
                NewObject := unique_object:
                    MemoryIntensiveArrays := array:
                        HugeFloatArray
                        HugeFloatArray
                        HugeFloatArray
                        HugeFloatArray
                        HugeFloatArray
                        HugeFloatArray
                        HugeFloatArray
                        HugeFloatArray
                        HugeFloatArray
                        HugeFloatArray

                if(not SomeWeakMap[Player]):
                    option. set SomeWeakMap[Player] = array{}
                option. set SomeWeakMap[Player] += array{NewObject}

                Print("Itration({I})")
                Sleep(0.0)
                # NewObject should be removed by garbage collector upon disconnection