Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

iOS Bundle-loading memory, on loading text-asset

Discussion in 'iOS and tvOS' started by Dessouky, Sep 11, 2015.

  1. Dessouky

    Dessouky

    Joined:
    Sep 10, 2015
    Posts:
    1
    I have a large xml file which is loaded from a TextAsset in an asset bundle, once loaded I parse the elements and use the data contained to create a database of objects with various features and parameters.

    There is a surprisingly large memory spike when I assign the TextAsset.text to a string, or read it using a string reader. I can manage all memory increases due to the bundle itself, by unloading the bundle, unloading unused assets and destroying the text asset. but nothing I do seems to get rid of the increase created by assigning the TextAsset.Text to a string. I've added the code snippet I'm testing below.


    This part works just fine, the memory used by loading the bundle request and the Text asset is released when I destroy the textasset and unload unused assets

    Code (CSharp):
    1. if (bundle.mainAsset != null)
    2.                 {
    3.                     AssetBundleRequest request = bundle.LoadAssetAsync("data", typeof(TextAsset));
    4.  
    5.                     yield return request;
    6.  
    7.                     TextAsset xmlFile = request.asset as TextAsset;
    The Parser.Xml is a string, I've also tried directly loading it to an XMLDoc, and using a stringReader, once it loads the text into the string, the memory goes up and will not go down no matter what I do after

    Code (CSharp):
    1. parser.Xml = xmlFile.text;
    This is more or less everything I could think of to release the memory

    Code (CSharp):
    1.                     parser.Xml = null;
    2.                     DestroyImmediate(xmlFile,true);
    3.                     System.GC.Collect();
    4.                     request = null;
    5.                     bundle.Unload(true);
    6.                     Resources.UnloadUnusedAssets();
    7.  
    8.        }
    I'm not really sure if its a memory leak or if I'm missing something here, this issue seems to only happen on iOS device (profiled using instruments). Don't see any evidence of it when I profile memory in editor
     
  2. perlohmann

    perlohmann

    Joined:
    Feb 12, 2009
    Posts:
    221
    It is worth to note that the data xml file is 20+ mb.
     
  3. perlohmann

    perlohmann

    Joined:
    Feb 12, 2009
    Posts:
    221
    bump =(