Weak maps don't hold weak references??

Please select what you are reporting on:

Creative

What Type of Bug are you experiencing?

Assets

Summary

I always thought weak maps would hold weak references, which seemed obvious to me

So I tested it out, and either my test script is wrong, or the weak maps are just broken (and never even worked?)

If weak maps don’t hold weak references, please update the docs to say so

Related? : Classes never garbage collected?

Steps to Reproduce

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

After 300 iterations (10s) both map or weak_map cause a server crash
But it should only happen with maps (or in a transactional context?), memory should be freed up whenever the reference to the weak map key is not held anymore

Tried the same thing over the course of 5min (in case garbage collector would not happen instantly) and the results are the same

Observed Result

Weak maps behave exactly the same as normal maps memory wise…

Platform(s)

PC

UCB-1309 incident has been created. Status is ‘Awaiting Validation’.

1 Like

Please don’t mind for now, I’m looking at it, garbage collector seem to just act funny

Found something worse probably related

Bump, still not validated ?