Memory Leak when using Play In Editor

I suspect there is a memory leak when using Play-In-Editor.

I am using a (very slightly modified) version of the Shooter Game Example project. Whenever I use the Play-In-Editor option for testing, I see the memory usage of the UE4Editor.exe process rise in the Windows Task Manager. This is to be expected, considering characters, weapons, controllers, etc. are spawned and initialized for gameplay. However, the memory usage does not drop back down when quitting play-mode and returning to the editor. I can also repeat this process a number of times (entering play-mode and leaving again), and every time the memory usage will increase again and never drop, so after a large amount of tests this can result in the computer running out of memory and would require re-starting the editor in between tests to clean up again.

In the basic Shooter Game Example project this is not a big problem yet, but it becomes a much larger issue when I turn on my own new code that I actually want to test, because it is creating large numbers of small objects quite rapidly. Many of these objects should be garbage-collected (I am creating them using the NewObject() function to create them, and most of them should also stop being referenced quite rapidly again and therefore be garbage collected), but the memory usage really increases rapidly with this code running and never goes back down again.

Normally I would expect this to be a mistake on my part, leaving the objects referenced somewhere so that they cannot be garbage collected, but given what I described above, that the same problem occurs on a smaller scale without any of my new code running, I suspect the issue may be in the Engine’s garbage collection itself. Also, even if I messed up my code and left references to my new objects, I would still expect them to get cleaned up when leaving play-mode.

I have also used the ‘memreport -full’ console command, once during gameplay and once with the editor still open after leaving play-mode. In the first log (during gameplay) in the Object List I could see reasonable counts of the objects of my new classes being alive (which makes sense, since during gameplay my code is running and creating some of these objects). In the second log (after leaving play-mode), these objects of my new classes no longer showed up in the Object List (indicating that they appear to have been cleaned up), but the Process Physical Memory (both used and peak) were HIGHER than during gameplay.

  1. Is this a known issue? I have seen reports of memory leaks on answerhub, but most of them seem to be about using the editor for a long time and not necessarily about using Play mode.

  2. Does anyone have any ideas for workarounds to force my objects to get garbage collected?

I’m using Unreal Engine version 4.9.2.

Hello DennisSoemers,

Have you tried to see if this issue occurs when using the Standalone game option instead of the standard PIE? Also, can you see if the same issue occurs outside of Shooter Game (i.e. in a fresh project) when just using your code? Unfortunately I didn’t have any luck reproducing the memory leak you were seeing with the base Shooter Game. If the issue does continue to occur outside of Shooter Game, can you post the code for the spawning that you’re doing?

Hello,

A while later I posted the same question in the Bug Reports section, thinking that it was a problem on the engine’s side and not in my code. In the meantime, I think I have identified the cause of the problem I was experiencing, see my comments here: https://answers.unrealengine.com/questions/323250/memory-leak-when-using-play-in-editor-1.html

I see, thank you for replying and letting me know that there was another post. I’ve converted your comment to an answer for this post and I’ll be marking it as resolved. If anyone else has any comments/questions about this issue, please refer to the link above. It would be best to keep all of the information in the same place.