0

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)

CodeSmile
  • 64,284
  • 20
  • 132
  • 217
  • How did you measure memory consumption? **When** did you measure it? Have you checked live objects in Instruments to ensure the involved objects have been released? – CodeSmile Mar 05 '14 at 10:31
  • I think images are cached unless a memory warning is given or user empties the cache manually. – Reza Shirazian Mar 05 '14 at 21:28

0 Answers0