Extreme lag persists after destroying actors?

I have a dungeon generation system that spawns dungeon rooms in a snake/tunnel fashion, where each branch checks if it overlaps another or itself. If it does it destroys each actor in that branch and regenerates it again. However, Ive noticed when the gen system is finished and Im left with my dungeon, even if it failed to create the first long branch and destroyed every actor in the scene, I still have intense frame drop. Are the actors continuing to be held in memory or something even after destroying them? Ive also made sure the generation actor is destroyed as well. Nothing is ticking.

The system potentially spawns and destroys hundreds to thousands of actors during the process. This is mainly because I haven’t optimized the algorithm yet

I have terrible frames when both playing as the character or just simulating in the editor

Hey @Baja3k!

You may want to choose to do something like a check in front BEFORE the spawning of objects, in chunks. Otherwise… Yeah you need to do a cleanup. Which, garbage collection tends to run often enough that it shouldn’t be an issue.

I would check through your code very carefully to make sure everything is indeed getting destroyed, instead of hidden etc. Destroying makes it marked for garbage collection.

That being said… It could be a multitude of other issues. Tons of dynamic lighting (Because you can’t bake it with this system) can do it as well, among many other things.

Hey, thanks so much for the reply. So if I understand correctly, if I use ‘Destroy Actor,’ it should mark it for garbage collection and once its gets “collected” is should be gone and not leave anything behind in memory or anything, which is what I’m doing. When my dungeon detects a collision, it runs through a loop destroying each actor in that branch of the dungeon before trying again. However even if the game starts with every dungeon piece that was placed being destroyed (so it tries to build the dungeon multiple times but in the end everything ends up deleted) I have terrible frames as if it’s all still there but I cant see it. I don’t have any dynamic lights in the dungeon right now. Could you explain what you mean by doing a check before spawning. Check for what exactly. Check that the previous ones were deleted before redoing the branch? Also a little more information, my dungeon rooms that are generated are created from many modular nanite pieces like walls, floors, pillars etc which isnt great for performance I’m sure, perhaps that is affecting it. I was planning to combine the meshes into one inside UE5. It’s just bizzare to me they can be deleted with ‘Destroy Actor’ and not be seen in the scene yet still have bad framerate afterwards. Maybe my blueprints mess with the garbage collection because it’s not well optimized and the game freezes for 10-15 seconds when generating the dungeon. Maybe I should use some short delays after each branch to give it a second to breathe? Who knows lol

I actually just read this "You should never ever allocate and destroy anything rapidly “At a rapid rate” - If you are doing this then you should be using a spare list. And reusing those allocations.

Also you cannot simply force a garbage collection any time you want. There are specific points in the update loop where it is possible." Which quickly creating and destroying is exactly what I am doing. Seems it is a garbage collection issue as you stated!