Hi!
I'm loading a new scene and this scene load graphics. When i close this new scene i want recover ALL the memory and i can't.
This is the code:
default.h:
@interface DefaultLayer : CCLayer {
bool bPuedoSalir;
}
@end
@interface DefaultScene : CCScene {
}
@end
default.m
//------------------------------------------------------------------------------
@implementation DefaultScene
- (id) init {
self = [super init];
if (self != nil) {
[self addChild:[DefaultLayer node] z:1];
}
return self;
}
@end
//------------------------------------------------------------------------------
@implementation DefaultLayer
//------------------------------------------------------------------------------
-(void) print_free_memory {
mach_port_t host_port;
mach_msg_type_number_t host_size;
vm_size_t pagesize;
host_port = mach_host_self();
host_size = sizeof(vm_statistics_data_t) / sizeof(integer_t);
host_page_size(host_port, &pagesize);
vm_statistics_data_t vm_stat;
if (host_statistics(host_port, HOST_VM_INFO, (host_info_t)&vm_stat, &host_size) != KERN_SUCCESS)
NSLog(@"Failed to fetch vm statistics");
/* Stats in bytes */
natural_t mem_used = (vm_stat.active_count +
vm_stat.inactive_count +
vm_stat.wire_count) * pagesize;
natural_t mem_free = vm_stat.free_count * pagesize;
natural_t mem_total = mem_used + mem_free;
int iUsed = round(mem_used/100000);
int iFree = round(mem_free/100000);
int iTotal = round(mem_total/100000);
NSLog(@"used: %d free: %d total: %d", iUsed, iFree, iTotal);
}
//------------------------------------------------------------------------------
- (id) init {
if( ![super init] )
return nil;
self.isTouchEnabled =YES;
[self print_free_memory];
[[CCAnimationCache sharedAnimationCache] removeAnimationByName:@"peli_arcade"];
[[CCSpriteFrameCache sharedSpriteFrameCache] removeSpriteFramesFromFile:@"video_fase1_HD.plist"];
[[CCSpriteFrameCache sharedSpriteFrameCache] removeUnusedSpriteFrames];
[[CCTextureCache sharedTextureCache] removeUnusedTextures];
[CCTextureCache purgeSharedTextureCache];
[self print_free_memory];
return self;
}
//------------------------------------------------------------------------------
- (void) ccTouchesEnded: (NSSet *)touches withEvent: (UIEvent *)event {
[[CCDirector sharedDirector] replaceScene: [test1Scene node]];
}
@end
And this is second scene that load graphics:
test1.h
#import <Foundation/Foundation.h>
#import "cocos2d.h"
@interface test1Layer : CCLayer {
}
@end
@interface test1Scene : CCScene {
}
@end
test1.m
@implementation test1Scene
//------------------------------------------------------------------------------
- (id) init {
self = [super init];
if (self != nil) {
[self addChild:[test1Layer node] z:1];
}
return self;
}
@end
//------------------------------------------------------------------------------
@implementation test1Layer
- (id) init {
if( ![super init] )
return nil;
self.isTouchEnabled =YES;
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"video_fase1_HD.plist"];
CCSprite * peli_arcade= [CCSprite spriteWithSpriteFrame:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:@"fase1_1.jpg"]];
CCAnimationCache *animCache = [CCAnimationCache sharedAnimationCache];
CCAnimation *animation = [animCache animationByName:[NSString stringWithFormat:@"peli_arcade"]];
if (animation==nil) {
NSMutableArray *animFrames = [NSMutableArray array];
for(int i = 1; i <= 49; i++) {
CCSpriteFrame *frame = [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:[NSString stringWithFormat:@"fase1_%d.jpg",i]];
[animFrames addObject:frame];
}
animation = [CCAnimation animationWithFrames:animFrames delay:0.2];
[[CCAnimationCache sharedAnimationCache] addAnimation:animation name:[NSString stringWithFormat:@"peli_arcade"]];
[animFrames removeAllObjects];
}
[peli_arcade runAction: [CCRepeatForever actionWithAction:[CCAnimate actionWithAnimation: animation]]];
[peli_arcade setPosition:ccp(360,218)];
[self addChild:peli_arcade z:2];
return self;
}
//------------------------------------------------------------------------------
- (void) ccTouchesEnded: (NSSet *)touches withEvent: (UIEvent *)event {
[[CCDirector sharedDirector] replaceScene: [DefaultScene node]];
}
@end
The program start with this:
used: 842 free: 1003 total: 1846
When the control return to the first scene and i delete ALL the graphics i have this
used: 882 free: 963 total: 1846
Why i'm losing this kb??