While debugging my app I found a strange problem that I can't figure out: at the start of every scene i load some textures asynchronously because I need them later and I want to speed up the loading. I put the texture loading in an event listener called when the scene is added to the stage. I frequently encounter some memory problems with the profiler after the scene change. I reproduced the problem in the scaffold project but I used a "touch event" instead of a "added to stage" event to trigger the texture loading. At every touch (or scene reload in my app) I see the memory consumption going up and not being released.
To test it you can just replace the code with this, and touch the image a few times while watching the profiler:
//
// Game.m
// AppScaffold
//
#import "Game.h"
#import "SXPSBlendModeFilter.h"
@implementation Game
{
SPSprite *_contents;
}
- (id)init
{
if ((self = [super init]))
{
// [self setup];
SPImage *image = [SPImage imageWithContentsOfFile:@"atlas.png"];
[self addChild:image];
[image addEventListener:@selector(onTouch:) atObject:self forType:SP_EVENT_TYPE_TOUCH];
}
return self;
}
- (void)onTouch:(SPTouchEvent*)event
{
SPTouch *touch = [[event touchesWithTarget:self] anyObject];
if ([touch phase] == SPTouchPhaseEnded)
{
[SPTexture loadFromFile:@"background.jpg"
onComplete:^(SPTexture *texture, NSError *outError)
{
}];
[SPTexture loadFromFile:@"atlas.png"
onComplete:^(SPTexture *texture, NSError *outError)
{
}];
}
}
@end
UPDATE: It seems to happen even if I call "loadFromFile..." from the init, not just from an event listener.