Search Unity

  1. If you have experience with import & exporting custom (.unitypackage) packages, please help complete a survey (open until May 15, 2024).
    Dismiss Notice
  2. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice

memory crash problem

Discussion in 'iOS and tvOS' started by chishti, Jan 7, 2013.

  1. chishti

    chishti

    Joined:
    May 21, 2009
    Posts:
    188
    Hi,

    I am using GUI graphics to load from an external path. I include these GUI Graphics in my exported xCode project. I have to use my Character GUI avatars from external path (reason for loading externally is to include In App Purchase for new bought characters), and have to load different graphics for Ratina and Simple iPad. All other graphics like Buttons, backgrounds etc... I am using them in Resources Folder of my unity project. So only my Character graphics have to be loaded from an external path. I am using this code to load character avatars.

    Code (csharp):
    1.  
    2. public Texture2D getTexture2D(string forPath) {
    3. Texture2D tex = new Texture2D(256, 256);
    4. tex.LoadImage(System.IO.File.ReadAllBytes(forPath));
    5. tex.Compress(true);
    6. return tex;
    7. }
    8.  
    I have different type of characters, So when I load different characters 4, or 5 times in my Character loader window, application crashes.
    As I can not use Resources.UnloadAsset, because I am not loading them from resources.
    To resolve this, I tried to use GC.Collect() to release memory. I called this after every 2 times opened Character Loader. But not working.

    I am interested to use Resources folder for characters but I will not be able to copy new bought characters in Resources folder when project is live.

    Any idea/Solution for the problem/memory crash?

    thanks
     
  2. xiongmaoboshi

    xiongmaoboshi

    Joined:
    Mar 15, 2012
    Posts:
    44
  3. chishti

    chishti

    Joined:
    May 21, 2009
    Posts:
    188
    no it still crashing :(
     
  4. Mantas-Puida

    Mantas-Puida

    Joined:
    Nov 13, 2008
    Posts:
    1,864
    Depending on your image format loading images that way may bring excessive memory allocation overhead.
    AssetBundles loaded via WWW.LoadFromCacheOrDownload might be better solution.
     
  5. chishti

    chishti

    Joined:
    May 21, 2009
    Posts:
    188
    OK today I will try that also.

    My application was using a heavy use of GUIs ( like buttons, DrawTexture, GUIGroup, Label ). What I did is to optimized the code in a way so that it draws the GUIs that are view able in my custom scroll.
    Also I reduced the memory size of some of character images by decreasing its DPI/Resolution value to 30.

    These two steps made difference on crash.