# Weak maps don't hold weak references??

**URL:** <https://forums.unrealengine.com/t/weak-maps-dont-hold-weak-references/1720472>\
**Category:** Issues and Bug Reporting\
**Tags:** fortnite-creative, unreal-editor-for-fortnite, fortnite\
**Created:** [February 29, 2024, 2:54pm UTC](https://forums.unrealengine.com/t/weak-maps-dont-hold-weak-references/1720472 "2024-02-29T14:54:48Z")\
**Posts on this page:** 9\
**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, 2:54pm UTC](https://forums.unrealengine.com/t/weak-maps-dont-hold-weak-references/1720472/1 "2024-02-29T14:54:49Z")

</div>

### 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?](https://forums.unrealengine.com/t/classes-never-garbage-collected/1720618)

### Steps to Reproduce

```auto
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

---

<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, 3:19pm UTC](https://forums.unrealengine.com/t/weak-maps-dont-hold-weak-references/1720472/2 "2024-02-29T15:19:51Z")

</div>

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

---

<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, 3:22pm UTC](https://forums.unrealengine.com/t/weak-maps-dont-hold-weak-references/1720472/3 "2024-02-29T15:22:52Z")

</div>

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

---

<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:09pm UTC](https://forums.unrealengine.com/t/weak-maps-dont-hold-weak-references/1720472/4 "2024-02-29T16:09:14Z")

</div>

Found something worse probably related

> [@Classes never garbage collected?](https://forums.unrealengine.com/t/classes-never-garbage-collected/1720618):
>
> 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 using { /Fortnite.com/Devices } using { /Verse.org/Simulation } some\_class := class: MemoryIntensiveArrays : [][]float test\_garbage\_collector := class(creative\_device): OnBegin\<override\>()\<suspends\>:void= …

---

<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/weak-maps-dont-hold-weak-references/1720472/5 "2024-10-22T06:30:27Z")

</div>

Bump, still not validated ?

---

<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:19pm UTC](https://forums.unrealengine.com/t/weak-maps-dont-hold-weak-references/1720472/6 "2024-12-16T16:19:29Z")

</div>

Really interesting!!! Quick fix please Epic ☹

---

<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:** [September 2, 2026, 2:48pm UTC](https://forums.unrealengine.com/t/weak-maps-dont-hold-weak-references/1720472/7 "2026-09-02T14:48:46Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![rhyan.smith](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/rhyan.smith/32/1218554_2.png) [@rhyan.smith](https://forums.unrealengine.com/u/rhyan.smith)\
**Post date:** [September 2, 2026, 4:32pm UTC](https://forums.unrealengine.com/t/weak-maps-dont-hold-weak-references/1720472/8 "2026-09-02T16:32:41Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![rhyan.smith](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/rhyan.smith/32/1218554_2.png) [@rhyan.smith](https://forums.unrealengine.com/u/rhyan.smith)\
**Post date:** [September 2, 2026, 4:33pm UTC](https://forums.unrealengine.com/t/weak-maps-dont-hold-weak-references/1720472/9 "2026-09-02T16:33:00Z")

</div>


