I have a class like that:
class ContentManager : IDisposable
{
List<int> idlist = new List<int>();
public int Load(string path)
{
//Load file, give content, gets an id
//...
int id = LoadFile(myfilecontent);
idlist.Add(id);
return id;
}
public void Dispose()
{
//Delete the given content by id, stored in idlist
foreach(int id in idlist)
{
DeleteContent(id);
}
}
}
I want to make it static, because i need only one instance and can access the function from every other class without giving an instance.
I can make every variable in it static and the functions static.
But my problem is this IDisposable. I cannot have Interfaces in static classes. How can i do some action at the end? I mean i can remove that interface but leave the function in it and use my main class and when my main class gets disposed i call ContentManager.Dispose(). But when i forget that in my main...
Do you have a good solution for that? Make sure that Dispose is called every time when the program gets closed?
Edit: I load data in a graphic card and get the pointer back. When my application closes, i need to delete the contents from the graphics card. To be safe, everything is deleted, i use dispose.