'audio' memory leak

Which is impressive, because I have 0 audio files in this project.

6162240--673893--upload_2020-8-3_17-23-39.png

Heya!
Which version are you using? :slight_smile:

Would you be able to provide some repo steps as to how you got to this point?
Could you take a snapshot with the memory profiler (be aware that pre-19.3 versions have somewhat large memory overhead when capturing)

Furthermore the numbers seen in the screenshot above, for the Audio category don’t add up at all :open_mouth: that might be another bug as we’ve recently changed the memory stats to profiler counters.

Cheers,
Alex

Ok woke up this morning, first time hitting play didn’t happen, ‘only 2.5GB’ of audio memory was allocated.
But hitting play the second time audio memory just started growing slowly, a few MBs per frame in the audio category.

This is in 2020.2.0a19. The scene I’m in is mostly just 1 large subscene with about 9000 objects with hdrp and hybrid renderer v2.
I’m not sure how to create a small repo for this, but I can get you some profile data.

The memory profiler doesn’t really match Unitys memory usage

6169175--675068--upload_2020-8-5_7-41-13.png

It doesn’t look very useful to me but if you want the actual memory profile data, I’ll upload it via bug report for privacy reasons.

-edit-

every time i hit play in editor, ‘audio’ memory in profiler jumps about 500MB

Started a new play, let it idle for 15min; 5GB more memory used but the memory profiler snapshot is nearly the same.

So it’d look like it’s Memory attributed to audio memory labels but not actually related to Audio NativeObjects (i.e. Something inheriting from UnityEngine.Object, like an Audio component or Asset). Because the Tree view you screenshoted only contains Objects, managed or native, but not all Allocations and buffers. These would be easier to see in the Memory Map and you should be able to spot that growth of usage in there by diffing and opening the Memory Map Diff view.

It would likely also be visible in the Raw tables like By Label…

Question: does this leak only occured when the CPU Profiler is recording and have you tried looking at this with the Audio Profiler module? You could also try disabling that module and see if that changes anything.

No, I first noticed it because I left scene running in background by accident, system started becoming sluggish and I looked and had 20GB+ of memory allocated.
The project as very little of my own code; I was playing around with hdrp (and hybrid renderer v2).

By default I have audio profiler disabled but I enabled it after seeing huge garbage though it reported pretty much nothing as you’d expect.

So I feel like I should have realized this, but somehow I did not know this about the memory profiler (and you’ve just helped me tremendously with a project at work).

I loaded up the same project, but couldn’t really get it to ‘leak’ memory again in the short time I tested it but it was jumping upwards of about 500MB memory every time I entered play mode (with the audio memory value was going up in the profiler).

Comparing 2 snapshots between 4GB (first play) and 6.5GB (about 7th play) the primary areas of new allocations were

A lot of blocks of this (one picked at random)
6179187--676665--upload_2020-8-7_20-19-22.png

And this
6179187--676668--upload_2020-8-7_20-19-44.png

And this
6179187--676674--upload_2020-8-7_20-20-53.png

And a few blocks of this
6179187--676677--upload_2020-8-7_20-21-24.png

And it all seems to be allocating to the Audio

6179187--676680--upload_2020-8-7_20-23-37.png

Maybe this view helps? (this was the second profile so has some of the profiler data)

Hi again,
We just found a bug with how Audio & Video Memory stats where reported in that simple view. Basically non-audio/video allocations to the same shared allocator the audio system uses could bump that number up. A fix for that reporting bug is in flight.

Are you using some Native plugins that could explain the difference in reserved total and Total System Used Memory? Native Plugin memory us not tracked by Unity’s Memory Manager and therefore would only show up in that Total System Used Memory (which is the memory as reported from the OS)

@MartinTilo
Other than native plugin, there is also a bug on the onaudiofilterread method implementation that allocate memory on every call. It’s there since around Unity 5 and has never been fixed, because the issue itself was introduced as a workaround for a scenario that would lead to a crash.
Maybe this is related to that? The bug number is 784161 and is open since 2016…

Since Unity’s profiler doesn’t seem to help here, would you mind trying to use Windows Performance Analyzer to see where the allocations are coming from? You can find a guide on how to use it here: VirtualAlloc Commit provider

According to the bug ticket, this should have been resolved since 2017.4, it just somehow never got verified and closer. Thanks for pointing that out. I’ve forwarded it to QA to retest and verify the fix.

Not fixed, I just checked around a month ago on 2019.3 or .4.

EDIT
Last time I checked only on the Unity profile, maybe what I see on the profiler is not memory allocated from the audio anymore, I should check with the Xcode profiler, it’s more clear there.

1 Like

Nah I have no plugins/dlls in the project at all other than ones that may be included in official Unity packages.

Just a random observation from examining memory on an xbox app the other day, but could it be ‘Allocator’ memory (nativearray, etc) as this didn’t seem to show up for me without looking at raw data on memory profiler.

Are you using DOTS then? Or some other Packages or Asset Store Plugins that might be allocating that much virtual memory for some reason?

tbh, this sounds more and more like a bug on our end but it’s always a bit tricky to tell in this space of memory.

Yes I’m using DOTS. The original post was mostly a large subscene of (12k) pure renderers; and that was about it.

I can’t seem to replicate the growing memory issue anymore. My memory is sitting much lower even with the same scene loaded. This project has been updated to the new version of entities/hybrid since the original post so that could have fixed it, or something else i randomly tweaked fix it. Such is the life of software development…

6217518--683637--upload_2020-8-18_20-33-45.png
6217518--683640--upload_2020-8-18_20-33-51.png

However memory being reported as audio still exist, but it sounds like you have a fix for that in the works.

2 Likes

aye, but good to hear that the original issue is gone now :slight_smile: