Is my UnloadContent method acceptable?

169 views Asked by At

I'm making a game in C# and XNA 4.0. It uses multiple assets that need to be unloaded when the game is closed. It uses multiple standard variables like double and int, but it also uses things like lists, contentmanagers and textures. I want to make sure that the current setup of the UnloadContent method will be able to unload the content properly. The code is set up similar to the following.

//These are the above-standard variables (Not like int, double and float)
List<string> myStrings; //List of strings
List<int> myInts; //List of integers
ContentManager contentOne; //This loads specific content
ContentManager contentTwo; //This loads other specific content
Texture2D myTexture; //This is loaded with "contentOne"
SoundEffect mySound; //This is loaded with "contentTwo"

//This is where the content is unloaded
void UnloadContent()
{
    //All of the content managers are unloaded
    contentOne.Unload();
    contentTwo.Unload();

    //All of the lists are cleared
    myInts.Clear();
    myStrings.Clear();

    //This is an added precaution
    Dispose()
}

As you can hopefully see, the method clears the lists and unloads the content managers. However, it does not do anything with the individual variables (the texture and soundeffect aren't modified in the method). Is unloading the content managers and clearing the lists all that I need to do? Also, is "Dispose()" a necessary method to call?

1

There are 1 answers

3
Robin Dijkhof On

Since c# is managed, you don't realy need to unload your content. This is done by the garbagecollector. Which means your content is unloaded automatically.

Check this question.