keijiro / KlakNDI

NDI® plugin for Unity

Home Page:https://ndi.video

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Memory leak, 2021.3.10f1 (not reproducible)

marvpaul opened this issue · comments

I found out that for one of my project the OS X build (intel) leads to a memory leak (ram usage for my app goes up very quickly, to over 10 GB within 1 minute) when using NDISender script attached to a Camera on an empty scene. When I disable the NDISender script, no memory leak occurs. This only happens when I run the built on my M1 Macbook, not when running the scene in the editor.

I tried to create a simple project to reproduce the issue, but in the test project I don't experienced a memory leak.

I'm using Unity 2021.3.10f1.

Do you have any idea where this could come from?

PS: Thanks for creating this project. I use it for several projects and it always worked like a charm beside of this issue!

Screenshot 2022-11-28 at 16 04 44

Screenshot 2022-11-28 at 16 06 18

The first images shows the empty scene in Unity, only NDI Sender script attached. The second screenshot shows my app "Vythm" with memory usage over 10GB (increasing even further).

I'd recommend using Memory Profiler to check where the leak comes from.

https://docs.unity3d.com/Packages/com.unity.memoryprofiler@1.0/manual/index.html

You can connect the profiler to built apps with the development build option.

@keijiro thanks for that. I already checked it out and can't find anything which gives a clue about high memory consumption. All three memory captures you can see in the screenshot were produced by the same application just running an empty test scene with the NDI Sender attached. Do you have any other idea what could cause it?
Screenshot 2022-11-28 at 17 53 21
Screenshot 2022-11-28 at 17 53 02

It seems like you're connecting to the Editor. How about switching it using the dropdown on the top-left of the window?

Also you can use the Compare Snapshots feature to get the delta amount of the memory consumption.

@keijiro Oh you're right, sorry for this!
Here it shows a snapshot which uses around 22 GB of RAM, mostly untracked memory. In the top left side it still shows "Editor", but I picked the actual app from the dropdown and closed it after creating the snapshot because otherwise it would cause a crash because of the memory leak.

Screenshot 2022-11-28 at 21 22 08

Screenshot 2022-11-28 at 21 20 13

My understanding is that "Untracked Memory" shows the amount of memory allocated by external code like native plugins. Do you use any other native plugin?

@keijiro thanks for this! Yes, I'm using a bunch like NatCorder and Unified MIDI. I'll just try to disable these ones and see if this helps. The reason why I'm wondering: The leak dosen't appear when I disable the NDI Sender component in the test scene. So this seems to be somehow related to your plugin (perhaps in coexistence with other plugins?).
Sadly it seems to be quite hard to examine which code exactly causes the leak. Is there any option beside the memory profiler to gather more information about memory usage of native plugins (so that I can see which plugin allocates the huge amount of RAM)?

I think you can use Instruments to investigate the memory issue in a more native way.

@keijiro Sadly I don't had any success so far to find the issue.

I removed all plugins and assets to create a sample project only with your NDI plugin included. When I build for Mac OS X (empty scene with active NDI Sender component) the application quickly blows up in ram usage above 10 GB.
Any idea why this happens?
I use Unity 2021.3.10f1. Interestingly enough, in another project of mine I use the exact same Unity version and your NDI plugin without the ocurence of a memory leak. The leak also only occur when I build for OS X and run on my macbook. When running in the editor, iOS or Android, it works fine without memory problems.
Here's the sample project:
https://github.com/marvpaul/NDI-memory-leak