Jump to content
  • Advertisement
Sign in to follow this  
Uphoreum

[.net] [XNA] Audio Disposal

This topic is 4167 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Do I have to call Dispose() on the AudioEngine, SoundBank, and WaveBank objects, or will the Garbage Collection system take care of that for me when the program ends? I'm still not entirely sure how much you're supposed to rely on the GC.

Share this post


Link to post
Share on other sites
Advertisement
Yes, everything gets properly cleaned up when the application exits. With the AudioEngine, you're probably only going to need one, so you really don't need to dispose it. Disposing is for freeing unmanaged resources *during runtime*. This is usually objects that manage connections and streams to other, external resources that are not under the control of the garbage collector, like files or network connections.

In the case of the AudioEngine, its unmanaged resources would be the connection to the XACT audition server. With the SoundBank, it's the file handles to scripts on disk for the sound definitions. With the WaveBank, it's the file handles to the raw wave files that will be played. I can't immediately conceive of a situation in which you would need a second AudioEngine, unless maybe supporting a system with two sound cards. If you don't have a lot of sounds for your game, or you're reusing the sounds between levels, then you'll probably only need one SoundBank and one WaveBank for the entire game, so you wouldn't need to dispose that either.

Now, if you have a lot of different sounds, and different levels that feature different sets of sounds, then you will want to consider disposing the Sound and Wave banks in between levels.

As for relying on the GC, the GC is very good in .NET. In Java, I've ran into situations where I needed to manually invoke the GC, because Java's GC only runs at specified intervals. Creating a large number of large objects in a short period of time meant the GC couldn't keep up with me, even though the earlier objects were long out of scope and unneeded. The .NET GC runs constantly, so it's much more agile about keeping up with object releases. As long as you no longer have a reference to the object anywhere, and it's not referencing any unmanaged resources (i.e., it doesn't have anything to dispose), then the GC will clean it up pretty well.

There are a lot of articles on MSDN about the garbage collector in .NET, performance with garbage collection, scenarios for using the IDisposable interface, etc. I suggest for you to get on there and start reading them, you'll gain a much better understanding of what is going on.

Share this post


Link to post
Share on other sites
Quote:
Original post by capn_midnight
....

As for relying on the GC, the GC is very good in .NET. In Java, I've ran into situations where I needed to manually invoke the GC, because Java's GC only runs at specified intervals. Creating a large number of large objects in a short period of time meant the GC couldn't keep up with me, even though the earlier objects were long out of scope and unneeded. The .NET GC runs constantly, so it's much more agile about keeping up with object releases. As long as you no longer have a reference to the object anywhere, and it's not referencing any unmanaged resources (i.e., it doesn't have anything to dispose), then the GC will clean it up pretty well.

...


While this shouldn't be too much of an issue for sounds objects (since you probably won't have thousands of them), it's good to bear in mind that the GC on the XBox works a bit differently from the one on your PC. More info about that can be found over here in this blogpost.

Share this post


Link to post
Share on other sites
Quote:
Original post by remigius
While this shouldn't be too much of an issue for sounds objects (since you probably won't have thousands of them), it's good to bear in mind that the GC on the XBox works a bit differently from the one on your PC. More info about that can be found over here in this blogpost.

A good article, though I would argue those types of optimizations would benefit any game under any runtime configuration.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!