Search Unity

Assembly Reload doesn't free all managed memory... Why?

Discussion in 'Scripting' started by LazloBonin, May 31, 2019.

  1. LazloBonin

    LazloBonin

    Joined:
    Mar 6, 2015
    Posts:
    813
    I was working on my asset (Bolt) recently and noticed I was getting ridiculously high RAM usage.

    The total GC allocated showed upwards of 1-2GB (!) values.

    So I thought I had a managed memory leak (not freeing a reference, etc.). I probably do somewhere. That I can fix, but it's not the problem.

    I tried entering playmode or recompiling to force an assembly reload and clear the memory.

    To my surprise, a whopping 1.9GB of the 2.2GB GC allocated just stayed there as a baseline memory!


    As far as I can remember, reloading assemblies always cleared all managed memory (which makes sense, because nothing holds a reference to anything anymore).

    What might be causing this? How can I fix it?

    upload_2019-5-31_14-1-42.png
     
  2. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,620
    I would attach a memory profiler and check what this 2gb is. This hopefully gives you then an idea how to fix it.
     
  3. LazloBonin

    LazloBonin

    Joined:
    Mar 6, 2015
    Posts:
    813
    Tried it; memory profiler hanged hard for 30 minutes on a very good computer, had to force quit Unity.
     
  4. LazloBonin

    LazloBonin

    Joined:
    Mar 6, 2015
    Posts:
    813
    The 2gb is undoubtedly memory I allocated though (because I only have my scripts in a blank project and it's all managed memory); that's not the issue. The issue is that it doesn't get freed on assembly reload, which I thought was supposed to be impossible?