I'm creating a game in C# and XNA 4.0. It consists of multiple levels with a player character, enemies, things to collect, etc. The levels are created using a Level class similar to the following.
List<Level> levels = new List<Level>(20); //This is a list to hold all of the levels (There are 20 levels in this example)
//This loop creates each level using a new instance of the class
for (int i = 0; i < levels.Capacity; i++)
{
levels.Add(new Level());
}
In order to add the enemies and such, I'm also using classes such as Enemy and Item. They are created in the same way.
List<Enemy> enemies = new List<Enemy>();
enemies.Add(new Enemy());
List<Item> items = new List<Item>();
items.Add(new Item());
The game is currently working as it should, but by the time it's finished I'll be using hundreds of new object instances. Can using too many new instances cause memory issues in C#? If so, how would anyone recommend reorganising the level/enemy/item creation to cut down on memory usage?