Can anybody explain how to free memory of a static member Variable? In my understanding it can only be freed if all the instances of the class are destroyed. I am a little bit helpless at this point…
Some Code to explain it:
class ball
{
private:
static SDL_Surface *ball_image;
};
//FIXME: how to free static Variable?
SDL_Surface* ball::ball_image = SDL_LoadBMP("ball.bmp");
From the sound of it, you don’t really want a pointer at all. In fact, since this is coming from a factory function in a C library, it isn’t really a “first-class” C++ pointer. For example, you can’t safely
deleteit.The real problem (if there is one) is to call
SDL_FreeSurfaceon it before the program exits.This requires a simple wrapper class.
When the program initializes, the constructor is called and the file is read. When the program exits, the destructor is called and the object is destroyed.