Search Unity

Memory leak in Canvas/ UI System

Discussion in 'UGUI & TextMesh Pro' started by devluz, Sep 12, 2015.

  1. devluz

    devluz

    Joined:
    Aug 20, 2014
    Posts:
    66
    Almost two weeks ago I found a memory leak in my program. If I use Destroy on a canvas Unity will not free the memory. If I keep destroying and recreating canvas's it will use more and more memory until the application crashes.

    This seems to be a massive bug to me and the 5.2 update doesn't solve it. I reported the bug almost 2 weeks ago still nothing happened. Currently, my work around is pooling everything that contains a canvas as good as possible :/ still hoping it gets fixed properly!

    Is there anything I can do to get this fixed?
     
  2. phil-Unity

    phil-Unity

    Unity UI Lead Developer

    Joined:
    Nov 23, 2012
    Posts:
    1,226
    2 weeks is not a lot of time. We currently have over 150 bugs assigned to our team. I dont even know if your bug has made it passed the QA verification and has reached us. You'll need to give it more time
     
  3. BIMG

    BIMG

    Joined:
    Oct 1, 2014
    Posts:
    16
    We found memory leak if you destroy Canvas with children (U 5.2.0 - 5.3.0). It looks like the workaround is destroy all children before destroying Canvas.
     
  4. phil-Unity

    phil-Unity

    Unity UI Lead Developer

    Joined:
    Nov 23, 2012
    Posts:
    1,226
    did you report a bug?
     
  5. carldevelopsforcoffee

    carldevelopsforcoffee

    Joined:
    Sep 20, 2017
    Posts:
    19
    Have a similar problem with a prefab with UI Image and UI Text. I load the prefab from an asset bundle. The Image has a sprite from at atlas within the asset bundle. The text has a font from the Assets folder (not in asset bundle).

    When I exit the scene, destroy the instantiated object of the prefab, and use Resources.UnloadUnusedAssets, the prefab and atlas remains in memory. WHY? This is due to the Text using a font that exists in Assets, it somehow keeps a reference to the prefab alive, thus all references within the prefab remain in memory.

    Note: References to prefab are somehow static, even when you stop the simulator in unity, the references will still show up in the memory detailed profiler view.