# Verse GarbageCollector issues

**URL:** <https://forums.unrealengine.com/t/verse-garbagecollector-issues/1407608>\
**Category:** Issues and Bug Reporting\
**Tags:** fortnite-creative, unreal-editor-for-fortnite, fortnite\
**Created:** [November 20, 2023, 9:20pm UTC](https://forums.unrealengine.com/t/verse-garbagecollector-issues/1407608 "2023-11-20T21:20:37Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Daigoro](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Daigoro](https://forums.unrealengine.com/u/Daigoro)\
**Post date:** [November 20, 2023, 9:20pm UTC](https://forums.unrealengine.com/t/verse-garbagecollector-issues/1407608/1 "2023-11-20T21:20:37Z")

</div>

### Please select what you are reporting on:

Verse

### What Type of Bug are you experiencing?

Verse

### Summary

The Verse GarbageCollector does not work properly.

### Steps to Reproduce

```auto
hello_world_device := class(creative_device):
    OnBegin<override>()<suspends>:void=
        Multiplier:=100000
        var I: int = 0
        loop:
            if (I>1000):
                break
            Print("Reached {I*Multiplier}")

            var J: int = 0
            loop:
                if (J>=Multiplier):
                    break
                One:=test_class{}
                set J+=1
            Sleep(0.0)
            set I += 1

```

### Expected Result

Verse should see that those objects aren’t referenced anywhere. It should clear those up.

### Observed Result

LogVerse: Error: VerseRuntimeErrors: Ran out of memory for allocating `UObject`s while attempting to construct a Verse object: test\_class!

### Platform(s)

All

---

<div class="post-metadata">

**Author:** ![LionUnchained](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/lionunchained/32/1039015_2.png) [@LionUnchained](https://forums.unrealengine.com/u/LionUnchained)\
**Post date:** [April 19, 2024, 3:05am UTC](https://forums.unrealengine.com/t/verse-garbagecollector-issues/1407608/3 "2024-04-19T03:05:01Z")

</div>

Based on my new understanding from the defer page:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/4/7/a/47a3296767a0e50cd4a12c46be06961d030bb3d9.png)

and looking up RAII:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/e/0/2/e023bc93cc9ee6cc9999f41e028d7a32ca2088bb.png)

I can conclude that you would have to exit the scope of your OnBegin in order to lose the reference to I, which would then garbage collect I.

For example, if you tried to access J from below set I += 1, the lack of reference is indicative that the value will be garbage collected.

---

<div class="post-metadata">

**Author:** ![Daigoro](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Daigoro](https://forums.unrealengine.com/u/Daigoro)\
**Post date:** [April 19, 2024, 4:00pm UTC](https://forums.unrealengine.com/t/verse-garbagecollector-issues/1407608/4 "2024-04-19T16:00:37Z")

</div>

> [@LionUnchained](#):
>
> I can conclude that you would have to exit the scope of your OnBegin in order to lose the reference to I, which would then garbage collect I.

This bug report isn’t related to `var I: int` or `var J: int` at all. The issue is that the `test_class{}` instances remain in memory even tho i leave their scope several times.

---

<div class="post-metadata">

**Author:** ![LionUnchained](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/lionunchained/32/1039015_2.png) [@LionUnchained](https://forums.unrealengine.com/u/LionUnchained)\
**Post date:** [April 19, 2024, 5:00pm UTC](https://forums.unrealengine.com/t/verse-garbagecollector-issues/1407608/5 "2024-04-19T17:00:24Z")

</div>

Oh wow, sorry I can’t read.

I think you need to have a sleep in this loop:  
 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/5/a/25a23364e0f291831ae879436315a09f5fd33113.png)

Assuming you likely know this at this point but I’ll try running this later and see what I can find on it.

I think I’ll go with a bit more straightforward test cases though, I got lost a few times on this one already XD

---

<div class="post-metadata">

**Author:** ![Kamyker](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/kamyker/32/1194621_2.png) [@Kamyker](https://forums.unrealengine.com/u/Kamyker)\
**Post date:** [April 19, 2024, 7:13pm UTC](https://forums.unrealengine.com/t/verse-garbagecollector-issues/1407608/6 "2024-04-19T19:13:11Z")

</div>

I don’t think that would help. Looks like a bug but maybe a workaround would be to put the loop in separate method.

---

<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:** [December 23, 2024, 2:35pm UTC](https://forums.unrealengine.com/t/verse-garbagecollector-issues/1407608/7 "2024-12-23T14:35:15Z")

</div>

FORT-733785 has been ‘Closed’. This issue won’t be fixed—please see examples of why this may be the case.

---

<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:** [January 5, 2025, 10:36am UTC](https://forums.unrealengine.com/t/verse-garbagecollector-issues/1407608/8 "2025-01-05T10:36:12Z")

</div>

Does this mean this will also not be fixed ?

> [@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= …
