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

769 views Asked by At

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?

2

There are 2 answers

3
Sunius On BEST ANSWER

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).

4
NPatch On

Unity has multiple backends. It has the Mono one which is C# and it has the IL2CPP one which is C++. Also release builds on Unity, afaiu, cannot be profiled.

Since we are talking about mods, perhaps do some test on whether it's your mod, or other loaded mods, or if it happens when you have multiple or specific ones loaded, or even on their own etc.