I’m able to load audio from an external directory by making use of the WWW class. The problem I’m having is that I can’t get the audio to unload and this is causing memory leaks.
I am loading audio like this and then storing all audio files in a dictionary for reference:
newAudioSource = gameObject.AddComponent<AudioSource>();
newAudioClip = new WWW("file:///" + absolutePath).GetAudioClip(false, false);
if (newAudioClip != null)
{
newAudioSource.clip = newAudioClip;
audioDict[audioKey] = newAudioSource;
}
and then I’m trying to unload the audio like this:
AudioSource sourceToRemove = audioDict[key];
audioDict.Remove(key);
Destroy(sourceToRemove);
But that’s not working because I can see the that the audio memory is not going down in the profiler. Eventually the app crashes because of too much memory.