Search code examples
c#unity-game-enginememory-leaksprofilerharmony

Unity Application Memory Leak - How can you profile without access to the source code or a debug target?


Bit of an unusual setup here,

  • I'm creating mods for the video game RUST
  • It uses HARMONY to load mods into the server code
  • At some point I did something to cause a memory leak, the application grows from 10GB in memory to 30GB over the course of a day with hundreds of players using it.
  • The mods are written in C#, but Unity's core is C++
  • Unloading all of the mods does not cause the GC to clean up the used memory, even when calling gc.collect manually.

I've tried hooking up traditional memory profilers like ANTS and dotMemory but they do not connect -- I'm sure that's to do with not having a release build or the fact that it's a Unity application.

I've tried attaching the Unity debugger, but it fails to recognize the game.

I'm running out of options, does anyone know if it's possible to ask the GC to dump what objects are currently being tracked? Perhaps its possible to use Harmony to hook into the actual allocation of memory step in the GC and I could track manually?


Solution

  • If you download the same exact version of Unity that the game was made in (you can check what it is in the properties page of UnityPlayer.dll), you can swap UnityPlayer.dll from a development build into the game and then use Unity's memory profiling tools. That said, this will only work if the game uses a relatively recent version of Unity (made within the last 3-5 years).