Memory leak when using loadImage

Hi.

As a rather newbie on Arduino programming I'm having a problem...

The following program works fine for a while, but after a few loops, it fails due to lack of memory. I have found the problem to be related with loadImage - but what do I have to do to solve the problem?

void loop(){ Serial.print("freeMemory() Loop = "); Serial.println(freeMemory());

ShowImage("logo.bmp"); ShowImage("rgb.bmp"); }

void ShowImage(char* filename){ PImage image;

myScreen.background(0,0,0); // clear the screen before starting again // load a image from the SD card image = myScreen.loadImage(filename); // check if the image loaded properly if (image.isValid() != true) { Serial.print("Error while loading "); Serial.println(filename); } else { //write the image on screen myScreen.image(image, 0, 0); } /* Serial.print("freeMemory() "); Serial.print(filename); Serial.print(" = " ); Serial.println(freeMemory()); */ delay(5000); }

My intention is to use a large number of images - so I can't just preload them... Anyone got an idea of what to do?