Playing sound causes gradual performance loss?

I’m really hoping this is something simple…

I’m working on an arcade game with lots of shooting and a ton of enemies. Just recently I added a number of sound effects for creatures dying and weapons being fired, and noticed that afterwards my iPhone builds suffered from a slow and steady performance drop after playing for several minutes - starting off in a healthy 25-30fps range, and slowly dwindling down to approximately half that, with noticeable dips when sounds are playing. Disabling my sound effects fixes the problem - the framerate stays consistent over very long tests, but adding the sound back in instantly causes the problem again without fail.

My file sizes for my sound effects are uncompressed to allow multiple sounds playing simultaneously, but are all very short and low fidelity to keep file sizes down. They range from 15k up to 85k, the larger ones playing less frequently.

The way I’m playing the sound is pretty straightforward - I have an AudioClip variable for each sound whos reference is assigned via the inspector, and I use the following code…

audio.PlayOneShot(variableName);

… to play them through my main audio source, which also has my audio listener attached.

By the time my framerate has deteriorated significantly, I’ve probably played some of these tiny 15k sound files a couple hundred times. This seems like it shouldn’t be that big of a deal though, arcade games kinda need to play a lot of sounds over and over… is the way I’m playing these sounds potentially causing some kind of memory leak?

Don’t use playoneshot.

Use:
audio.clip = mysound
audio.Play()

What about overlapping the same sound effect over itself? I should think the garbage collector should get rid of all the one-shot audio clips that were done playing.

Mr Animator could you submit a bug please.

As BlackSp1der suggested, playoneshot is the culprit.

After switching my scripts to use audio.Play() instead of audio.PlayOneShot(), the gradual loss of performance has been solved. I even did an extra long stress test to be sure, and my fps never faltered. This definitely sounds like a bug in PlayOneShot, and I’ve submitted a report, ReJ.

Rather than constantly swapping my audio.clip though, I chose to have a handful of empty game objects, each with their own audiosource component with different clips selected. So instead of having variables pointing to different audioClips like before, I now have variables pointing to different audioSource components, which allows me to play different ones simultaneously. And for certain sounds that need to be able to play over themselves (like rapidly firing weapons), I can just use two seperate audiosources and toggle back and forth between them.