I have identified the object that causes it, and even narrowed it down to being being caused by it's constructor/destructor. But yet, I cannot for the life of me figure out why it leaks memory, everything it allocates dynamically is deleted. Yet it leaks memory. The leak is only 5 byte according to the tool I'm using, so I could very well ignore it and the project would not really suffer from it; but I so would like to understand why it is happening.
The Constructor in question
//Automatically sizes object to image size
guiButton::guiButton(char* name, int posX, int posY, int priority, gameImage* image, scriptFunction* function)
{
this->image = image;
this->createObject(name, posX, posY, image->getSizeX(), image->getSizeY(), priority,0,0);
this->resizeImage = false;
this->guiButtonEvent = new gameEvent(gameEvent::eventGuiButtonClicked, this->id, function);
}
The Destructor
//Destructor
guiButton::~guiButton()
{
std::cout << "GuiButton destructor!\n";
delete this->guiButtonEvent;
}
And the objects header
//Simple button, clickable
class guiButton : public guiImage
{
protected:
//Event that is flagged once button is clicked
gameEvent* guiButtonEvent;
guiButton() {}; //Does nothing
public:
//Constructors
//Automatically sizes object to image size
guiButton(char* name, int posX, int posY, int priority, gameImage* image, scriptFunction* function);
guiButton(char* name, int posX, int posY, int sizeX, int sizeY, int priority, gameImage* image, scriptFunction* function, bool resizeImage);
guiButton(const guiButton& orig);
//Creates a clone of this object, as if through a copy constructor. Deleting it needs to be done manually
virtual guiObject* clone();
//Attempt to interact with the object, flags an event in the passed manager if it was interacted with.
void attemptInteraction(inputState* input, eventManager* manager) throw(std::exception*);
//Destructor
virtual ~guiButton();
};
And yes, the object is part of an inheritance hierarchy. But I have verified that it is at this level the leak occurs, as I can create guiImages without causing any kind of memory leak. guiImage also uses the exact
same call to the createObject function, so I doubt that is the cause, likewise gameEvent instances can be freely created without causing any kind of memory leaks.
Any help at all in figuring out what is going on would be greatly appreciated.






