[Solved] Force garbage collection on manually loaded world

I’m creating plugin that does offline generation on maps.

So I’m loading world, doing some work on it, mainly placing assets, and then I want to save it, close it, and open another one.

Problem is that those worlds don’t get garbage collected and I run out of memory after few.

I assumed that calling


followed by


would be enough. It wasn’t.

I tried marking world and package from which it’s loaded with


I cleared them standalone flags by hand


I even tried calling




on them and all objects that have them as outer collected from


I think I’m missing something. It surely is possible as I can load level and unload it in editor UI and world is properly cleaned(I check with memreport)

Hi, miniu, and welcome to the forums!

Please excuse me for questions that may seem stupid, but:

  1. Are you sure that there are no references left to those worlds and/or any actors placed on them? Because if there are they will not be GC’ed.

  2. Are you sure the OOM you are getting is related to those worlds being left in memory and not to some other memory that might have been leaked during the generation process?

Thanks for welcome :slight_smile:

@1 I assume that this is a problem probably. I just can’t find those references. This or I’m removing them incorrectly.
I’m doing same generation on loaded levels though and if I use UI to unload them I don’t get objects left over. So it seems to me that it’s related to either how I create these levels or how I unload them.

@2 Yes, I look at “memreport --full” and I see that the memory that is “leaked” are Hierarchical Instanced Meshes that I created, all of them from all the worlds I created and thought that I destroyed are still there. I also see that World objects count is same as number of worlds that I loaded.

Found FReferenceFinder and “obj refs” command. I’ll try to use it to find who references my levels.

Turns out it was validator checking if my save has gone properly.

I did save and unload on level at the same frame, next frame validator was checking if everything saved properly world was missing so it just loaded it again.

Hello, I’ve been developing plugin and encountered the same issue, could you be more specific about what is “validator checking” , like which function is doing the checking, thanks a lot.