This is something which has been bugging me. If I create a SoundEffectInstance via SoundEffect.CreateInstance() I’m meant to dispose of it when I’m finished with it. SoundEffect.CreateInstance() does not use ContentManager as far as i can tell.
So does it load from file or does it keep a copy in memory? Loading from file would obviously be very slow :-/
It’s an implementation detail. You don’t know for sure, it doesn’t matter, it might differ between platforms, and it might change in the future.
However you can make an educated guess: First of all the fact that
SoundEffectInstanceexists, and that you load sound files intoSoundEffectindicates thatSoundEffectis probably responsible for holding the sound effect in memory. And the existence ofSoundEffect.FromStreamand the buffer-basedSoundEffectconstructors are strong indications thatSoundEffectmust have a mechanism for keeping a sound buffer in memory. Therefore it is fairly safe to assume that when you load aSoundEffectfrom a file, it uses the same mechanism.If it’s really important, you could test it by deleting or modifying the sound file, after loading the
SoundEffect, and then creating an instance.As always, if performance is really important, you should measure it.
Of course, creating a
SoundEffectInstancedoes allocate resources (audio voices, managed and probably unmanaged memory). So it’s not something that you should be creating regularly if you can avoid it – such as by pooling and reusing instances. When you’re usingSoundEffect.Play, thenSoundEffectis internally managing a pool ofSoundEffectInstanceobjects for you.