Cocos2D CCTextureCache stays in memory

129 Views Asked by At

I load images in a asynchronous way, for a scroller, using addImageAsync.

I start profiling, and saw some memory issue, images stayed in memory.

Then I decided to compare addImageAsync vs spriteWithFile, with loading and directly unloading images. Once all the loadings are done, addImageAsync is using more memory.

In a loop that loads many images, if I use

    CCSprite* sprite = [CCSprite spriteWithFile:previewPath];
    NSLog(@"sprite created");
    [[CCTextureCache sharedTextureCache] removeTexture:sprite.texture];
    NSLog(@"texture removed");
    sprite = NULL;
    NSLog(@"sprite nulled");

I end up with 72.4MB

If I use:

    [[CCTextureCache sharedTextureCache] addImageAsync:previewPath withBlock:^(CCTexture2D *tex) {
        [[CCTextureCache sharedTextureCache] removeTexture:tex];
        NSLog(@"texture removed");
        [CCTextureCache purgeSharedTextureCache];
    }];

I end up with 108.7MB

Is there a problem here, or do I do something wrong ?

(using Cocos2d V2)

0

There are 0 best solutions below