Need help finding memory leak

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?

std::stringstream stream; maybe you can clear stream by stream.clear(),have a try.

You can trace into CCTextureCache::addImage(const char*) to check if
texture = (CCTexture2D*)m_pTextures->objectForKey(pathKey.c_str()) succeed.
If CCTexture2D cannot get “texture” successfully here, it will load the image file from file system.

Or you can try

void AnimalFaces2::updateAnimal() {
    std::stringstream stream;
    stream << currentAnimal << ".jpg";
    std::string animal = stream.str();

    CCTexture2D* texture = CCTextureCache::sharedTextureCache()->textureForKey(animal.c_str());
    if (!texture)
    {
        CCTextureCache::sharedTextureCache()->addImage(animal.c_str()));
    }

    bg->setTexture(texture);

    CCTextureCache::sharedTextureCache()->removeUnusedTextures();
}

std::stringstream is a local scope variable, it should be deleted on automatically. Besides, the memory leak doesn’t occur when the texture setting line is commented out. It appears now that it is a bug in the Mac port. I ran it on WebOS and the problem didn’t exist.
I’m still not sure why my CCImage, handData, is still leaking memory (on both platforms). Shouldn’t the new data overwrite the old data? Is there a way to do this that doesn’t leak memory? If not, I guess it would be trivial for me to add a release function to CCImage but I’d rather do things the “official” way if possible.