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:

[10538-screen+shot+2013-04-29+at+21.40.52.png|10538]

This is loading it without being in an Asset Bundle

[10539-screen+shot+2013-04-29+at+21.45.21.png|10539]

How can I get it to not use this memory?

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.

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.

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