Search Unity

Memory crash when calling Resources.UnloadUnusedAssets on Android

Discussion in 'Android' started by Lamosca_2014, Jun 25, 2015.

  1. Lamosca_2014


    Jan 26, 2015
    I have a memory crash when calling Resources.UnloadUnusedAssets on Android (using Unity 5.1.1 but in previous versions as well). The app just closes without any error message.

    The game shows photo's taken by other players so the player can like or dislike them.

    So this is the general flow, which is repeated:
    - load a texture:
    byte[] fileData = File.ReadAllBytes(filePath);
    Texture2D tex = new Texture2D(2, 2);

    - show the texture on screen (using tk2dSpriteFromTexture of the 2D Toolkit plugin)
    - destroy the texture:
    UnityEngine.Texture2D.Destroy (tex);
    - call Resources.UnloadUnusedAssets and GC.Collect():
    protected static IEnumerator DoMemoryCleanupCoroutine(Action callback)
    yield return Resources.UnloadUnusedAssets();
    yield return null;
    yield return null;
    if(callback != null)

    After executing this 100-120 times, the app crashes when calling Resources.UnloadUnusedAssets. The crash will not happen randomly: if I do the same flow for the same amount of times on multiple devices they will all crash at the same moment.

    I have attached the profiler and added debug logging to track the memory usage, and there seems no increase or anything strange with that. So it doesn't seem to be a memory leak.

    I've also tried to create a texture pool so the Texture2D object is kept in memory and not recreated every time, but this does not seem to have any influence.

    It seems that there is a bug in Resources.UnloadUnusedAssets that makes it crash after calling a certain amount of times on Android...
    On iOS this does not happen.

    Anyone encountered the same problem? Or have any idea to solve this?
  2. Jakhongir


    May 12, 2015
    Hello, have similiar situation crash happens on Resources.UnloadUnusedAsset, only after using Resources.Load<AudioClip>(). If Resources.Load <AudioClip>() is not used, no crash.
  3. Meltdown


    Oct 13, 2010
    Submit a bug report with a small repro project and post the case number here.