Does avaudioplayer save data to persistent storage?

Hi All,


I've got a strange situation where I've got an app that downloads and plays audio from the Internet sequentially (CB, in the app store), and while this hasn't been an issue historically, I've noticed that under iOS 10, the app's local storage space usage seems to grow by the amount of audio data that's playing.


The current in-store version is a little long in the tooth, and was built in Obj-C, so I figured I'd have some fun and rebuild it from the ground up in Swift. In both cases, I download the data into an in-memory object (NSData in the old one, Data in the new one), read it into the player object, play, then ice (set to nil) the the stored data object.


Nowhere do I save to disk. I'm perplexed; is there some default behavior that could cause AVAudioPlayer data--or even just downloaded data stuck into a Data object--is saved to persistent storage unless specifically being told not to?


Thanks!

Replies

If you're using one of the initWithData methods to initialize your AVAudioPlayer object. This data object is retained by AVAudioPlayer until the player itself is released. You can use the data property on your player instance to get a reference back to the object that is being retained by the player.

Makes sense; but is there a reason it should be getting saved to persistent storage? I'm literally not saving anything to a persistent file.

AVAudioPlayer wraps AudioQueue and the implementation is using AudioFile to "open" the data object with AudioFileOpenWithCallbacks (by nature this object is then not seekable and read only) as a file in memory. Reading is done with AudioFileReadPacketData and inUseCache is false. I don't see anywhere that this data would again be written to disk. Maybe there's a retain issue (which should be traceable) or something with the NSData implementation which I'm not familiar with?


So, if you have a data object and pass it to the player, then both objects are disposed, there should be nothing left. Should be a fairly easy test case to put together.