Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

'audio' memory leak

Discussion in '2020.2 Beta' started by tertle, Aug 3, 2020.

  1. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,761
    upload_2020-8-3_17-23-8.png

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

    upload_2020-8-3_17-23-39.png
     
  2. alexrvn

    alexrvn

    Unity Technologies

    Joined:
    May 16, 2017
    Posts:
    53
    Heya!
    Which version are you using? ^_^

    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 :O that might be another bug as we've recently changed the memory stats to profiler counters.

    Cheers,
    Alex
     
  3. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,761
    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
    upload_2020-8-5_7-40-25.png

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

    upload_2020-8-5_7-40-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
     
    Last edited: Aug 4, 2020
  4. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,761
    Started a new play, let it idle for 15min; 5GB more memory used but the memory profiler snapshot is nearly the same.

    upload_2020-8-5_7-57-58.png

    upload_2020-8-5_7-58-6.png

    upload_2020-8-5_7-58-44.png
     
  5. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,459
    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.
     
  6. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,761
    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)
    upload_2020-8-7_20-19-22.png

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

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

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

    And it all seems to be allocating to the Audio

    upload_2020-8-7_20-23-37.png
     
    Last edited: Aug 7, 2020
  7. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,761
    Maybe this view helps? (this was the second profile so has some of the profiler data)

    upload_2020-8-7_20-39-55.png

    upload_2020-8-7_20-40-29.png
     
  8. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,459
    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)
     
  9. 00christian00

    00christian00

    Joined:
    Jul 22, 2012
    Posts:
    1,035
    @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...
     
  10. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,680
  11. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,459
    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.
     
  12. 00christian00

    00christian00

    Joined:
    Jul 22, 2012
    Posts:
    1,035
    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.
     
    Last edited: Aug 18, 2020
    MartinTilo likes this.
  13. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,761
    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.
     
  14. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,459
    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.
     
  15. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,761
    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...

    upload_2020-8-18_20-33-45.png
    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.
     
    LeonhardP and MartinTilo like this.
  16. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,459
    aye, but good to hear that the original issue is gone now :)