- Home /
AudioManager memory usage on iOS when using Asset Bundles
So I appear to have suddenly got a huge amount of memory being used by AudioManager in my iOS game.
It's only occurring when I have the scene in an asset bundle.
All of the music for the scene is in the Resources folder (so it is included in the build) but is directly referenced in the scene.
The total size of the audio for this scene < 15MB.
Here you can see the effect:
This is loading it without being in an Asset Bundle
How can I get it to not use this memory?
The music for this game is set to stream from disc. I'm guessing that isn't working in a strea$$anonymous$$g scene Asset Bundle.
Changing the music to be Compressed in memory saved 40$$anonymous$$B
Answer by whydoidoit · May 01, 2013 at 06:54 AM
So it appears that including a stream from disk audio file in an Asset Bundle is a big memory hog. It looks like the whole track is loaded into memory uncompressed.
The answer is to compress music in memory and to avoid direct references in the scenes, rather load them from an individual track bundle when needed.
Okay, but I'm not using AssetBundles with my streamed audio. I have a game object in the scene with the music files attached to audio sources. They're all set to stream from disk. There is no loading of asset bundles involved - the only funny business is that the object they're attached to is set to DontDestroyOnLoad(). We have four songs, compressed their combined sizes total to something under 75 $$anonymous$$B. Yet the Audio$$anonymous$$anager object shows to be using almost half a GB.
After making the audio sources all Compressed in $$anonymous$$emory, the size of the audio manager became 45 $$anonymous$$B, audio clips taking up 75 $$anonymous$$B. (There are more audio files than just the songs.)
Though this isn't good enough. We expect to have a LOT of songs in our game. Surely they wouldn't have Stream from Disk as an option if it was, as it seems, completely useless.
Well Stream from disc worked for me before the asset bundles (see my second picture above), but failed dismally afterwards.
Answer by Sisso · Apr 29, 2013 at 09:09 PM
I dont know about asset bundles, but everything directly referenced by a scene is automatic load, do not matters if it is in Resources or not.
You normally use a Resources folder (in addition to the obvious) to ensure something is in the build (like shaders that are referenced in bundle's shaders fallbacks or used to create materials at runtime) - this would normally mean that it wasn't required in the asset bundle.
Answer by ferretnt · May 26, 2013 at 10:22 PM
Thanks for posting this Mike - hugely helpful when I was debugging iOS audio usage this weekend.
It seems that even without AssetBundles, using Stream From Disc on iOS is dangerous with short clips. I have just verified (both with Unity's profiler and Xcode) that if you have lots of short clips (like dialog), and select to stream them in from disc, you then get a single disproportionately large alloc, which shows up in the Unity memory profiler under Assets/AudioManager.
I currently have dialog totalling around 8Mb in a scene, and if I set all of it to "Compressed in Memory", then I get a 5.4Mb AudioManager allocation, plus the size of the compressed dialog under Assets/AudioClip. If I set it to "Stream from disc", then I get a ~64kb alloc per audio sample (presumably some header), plus a 15Mb audioManager alloc. The resulting ~10Mb difference between the two builds can be easily measured using Instruments' Activity Monitor.
Alex
Your answer
Follow this Question
Related Questions
Asset bundles using double memory! 1 Answer
mp3 files giving ios memory warning 0 Answers
some iOS devices took more memory about 200%!! 1 Answer
AssetBundle memory profiling 0 Answers