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

1 Like

Found something worse probably related

Bump, still not validated ?

Really interesting!!! Quick fix please Epic :frowning:

1 Like

Would it be possible to get some explanation regarding the exact behavior of weak maps as of today?

Hey @im_a_lama, first, thank you for reporting this!

I have reached out regarding this and people internally agree this sounds like a bug more than anything.

I can see this thread was made in 2024 which is beyond my days here but also seems like this bug report was created in a section I can’t access internally so I’m not sure if other people can.

That being said, if you could re-create your bug report and then tag me in the replies I can then get that sent to the correct people internally.

Going to close this thread so we can use the new one

1 Like