Memory leak around SDL FreeSurface When I call my tile engine function, the amount of memory my program uses begins to spike at about 80 90 megabytes per second. The memory use continues to go up until the program crashes. The function is below. After tinkering with it, I figured out that I could reduce this bricking to about 15 megabytes per second if I called SDL FreeSurface every time I ran the function. But this confused me, because I thought that you are only supposed to use SDL FreeSurface when the program exits so that the images don't continue to occupy the memory. if I don't call SDL FreeSurface before I blit the tiles, do the previously blitted tiles continue to exist? If I don't how do I fix the aforementioned bug? The edit I made to bring the memory bricking down to 15 megabytes per second is commented out. SDL Surface loadedTile NULL SDL Surface modelIMAGE NULL void enviroment blitTiles(SDL Surface windowENVIRO, int tileAmount, int tileType , int tileXenviro, int tileYenviro, bool quitTiles) HDcounter 1 if(loadedTile ! NULL) SDL FreeSurface(loadedTile) loadedTile IBFobjectENVIRO.loadIMG("tileClipSheet.png") for(int tiles 0 tiles lt tileAmount tiles ) switch(tileType tiles ) Black square (unpassable) case 1 IBFobjectENVIRO.blitIMG(tileXenviro 75, tileYenviro, windowENVIRO, loadedTile, 0, 0, 75, 75) HDcounter 1 forbiddenX HDcounter tileXenviro 75 forbiddenY HDcounter tileYenviro forbiddenSpriteWidth HDcounter 75 forbiddenSpriteHeight HDcounter 75 forbiddenSpriteDepth HDcounter 75 break Grey square case 2 IBFobjectENVIRO.blitIMG(tileXenviro 75, tileYenviro, windowENVIRO, loadedTile, 75, 0, 75, 75) break Brown square case 3 IBFobjectENVIRO.blitIMG(tileXenviro 75, tileYenviro, windowENVIRO, loadedTile, 150, 0, 75, 75) break Invisible square (unpassable) case 4 IBFobjectENVIRO.blitIMG(tileXenviro 75, tileYenviro, windowENVIRO, loadedTile, 225, 0, 75, 75) HDcounter 1 forbiddenX HDcounter tileXenviro 75 forbiddenY HDcounter tileYenviro forbiddenSpriteWidth HDcounter 75 forbiddenSpriteHeight HDcounter 75 forbiddenSpriteDepth HDcounter 75 break tileXenviro 75 if(tileXenviro gt level1ObjectENVIRO.level1Width) tileYenviro 75 tileXenviro tileXenviro level1ObjectENVIRO.level1Width if(quitTiles true) SDL FreeSurface(loadedTile)