False alarm! (read the edit)
I’m trying to make a small game, using SDL. When an entity is created, its image should up the refcount, and that’s no problem. The problem comes when it’s time to use “SDL_FreeSurface(image)” (do decrease it), this should happen within the entity itself so I’m trying to create my own destructor, as a test to see if it got called at all I added a cout, but it’s called every tick for some reason? It’s not deleting anything so I suppose I also have to take care of all the entities values when I do get it to work (thought that I only had to take care of the special cases, such as this).
Entity::~Entity()
{
cout << "I'm deleted" << endl;
//SDL_FreeSurface(image);
}
If destructors are supposed to be called all the time (?) why is that?
EDIT
I just realized that during each tick I use some temporary entities, it’s probably those that get deconstructed, sorry feel free to lock this.
Your destructor will be called every time an object of class Entity is destroyed and only then.
If your destructor is called at every tick, that means an object is destroyed at every tick. Likely you’re creating a temporary Entity object at every tick and it gets destroyed right away (for example you might be passing an Entity object by value).