How to unload unused references ??

I’m recently learning about better referencing to manage the memory usage of my big levels better. I learned that soft references are only loaded when needed.
However, how should we unload the unused references to free up more memory?
This is a topic that doesn’t get covered a lot in tutorials, so I hope to get some answer/hints here.
Thanks in advance!

1 Like

Garbage collection will take care of unused reference every 1min(can be change in setting) so for it to be unused it need not be stored in a variable or used by other object. You can also use Force GC but better to let GC do it own thing :innocent:

2 Likes

Thanks for the reply, so in case if I stored anything as soft reference variables, will they be taken cared of when not being used and GC does its job? Or I need to clear all soft reference variables manually before GC does the thing?

It fine storing as soft ref since they are not yet in memory, think about it like a string id of it path location class.
It only when you manually load that soft ref that it become a hard reference, and this hard reference will stay in memory, when that hard reference get destroy/unused , only then GC will take care of him.

You can play around with these variables in a bp and view it Reference Viewer to see what is/not in the memory.

Soft ref is slow to load, we usually use them for audio/image but for an animation attack, you might want this to load instantly (so hard ref might be better depending on your game and context), you also need to add some checking condition whether it still loading since Async Loading soft ref will queue when called multiple times.
If a user spam audio async load while still loading the 1st audio, you might get multiple same audio playing.

1 Like

Oh Ok, that’s much more clear now, well explained, thank you so much!

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.