Search Unity

Loading compressed wav iOS keeps too much memory

Discussion in 'Scripting' started by Deathfate, Mar 23, 2017.

  1. Deathfate


    Sep 10, 2012
    Hello I am using this code to load a wav file compressed in memory, they are around 3 minutes and 30 seconds long.

    Code (CSharp):
    1. static IEnumerator LoadWavCompressedRoutine(string filename, Action<AudioClip> onLoadedAction){
    2.         using (WWW w = new WWW("file://" + filename))
    3.         {
    4.             yield return w;
    5.             if (string.IsNullOrEmpty(w.error))
    6.                 onLoadedAction(w.GetAudioClipCompressed());
    7.             else
    8.                 onLoadedAction(null);
    9.         }
    10.     }
    The code works fine but when I see in Instruments the memory allocated There are 2 kinds of allocations, one is the w.GetAudioClipCompressed() allocation that is around 17mb but there is another of 32.0mb of

    dynamic_array<unsigned char, 1ul>::insert(unsigned char*, unsigned char const*, unsigned char const*)
    DownloadHandlerBuffer::OnReceiveData(void const*, unsigned long)
    iPhoneWWWDownloadBuffer::OnReceiveData(void const*, unsigned long)
    [UnityWWWConnectionDelegate connection:didReceiveData:]

    I think this memory is from the bytes downloaded via WWW but Once I have my audio i would want to release that memory. It is true that if I destroy the created audio both allocations go away but I am wondering if this WWW memory is needed once I have my audio or if there is a way to get rid of it.

    I filled a bug report on this, case number 894233

    Thank you.
    Last edited: Mar 23, 2017