I have an app that has a background image that should change when the user clicks a button. It works fine, but every time the button is clicked the memory usage goes up by about a megabyte. Here is the function that is called when the button is clicked:
void AnimalFaces2::updateAnimal() {
std::stringstream stream;
stream << currentAnimal << ".jpg";
std::string animal = stream.str();
bg->setTexture(CCTextureCache::sharedTextureCache()->addImage(animal.c_str()));
CCTextureCache::sharedTextureCache()->removeUnusedTextures();
}
The image files are certainly being cleared, or else it would jump up far more than a megabyte, but what isn’t being cleared?
On a related note, I was also using a CCImage to do collision detection for each background. I don’t know how to release that data because calling release on a CCImage gives a linker error that the symbol was not found and calling delete() on the image does nothing. The code to load that is:
stream.str(std::string());
stream << currentAnimal << ".jpg";
std::string collision = "collision" + stream.str();
handData->initWithImageFile(collision.c_str(), CCImage::kFmtJpg);
The code is commented out now, because it is clearly a memory leak, so it isn’t related to the 1mb increase problem above. How do I release this data?