I’ve been looking for over 2 hours and it turns out my memory leak is coming from this section, only I am unable to determine what is causing the leak. BTW, I am using Allegro5, but made some wrappers.
void WidgetLabel::updateBitmap( Display* display )
{
Size textSize = getTextSize( _font, _text.c_str() );
_bitmap = createBitmap( textSize.getWidth(), textSize.getHeight(), display );
startDrawingToBitmap( _bitmap );
drawText( _font, _color, Point(0,0), _text.c_str() );
stopDrawingToBitmap( _bitmap, display );
}
Edit: I thought I might need to delete the _bitmap to free the space before creating a new one, but the application keeps crashing when doing so. I am guessing it is because of how Allegro manages memory. With Allegro, you must do:
al_destroy_bitmap( ALLEGRO_BITMAP* bitmap );
Assuming that
createbitmapallocates memory, are you overwriting_bitmapalways, when you callupdateBitmap()? (Is there any statement you are missing to manage_bitmap?)It might crash, if
_bitmapis not initialized and you are trying tofreeit. You can initialize_bitmapin constructor as0and then check for NULL before freeing it. i.e.