Hi all,
I'm trying to release memory used by a UIViewController containing a UIImageView
but that doesn't work on device.
That seems to work perfectly on Simulator, not on iPhone.
I'm NOT using [UIImage imageNamed] to avoid using the cache of the iPhone.
I'm using a NSMutableDictionary to store all UIImage (loaded with imageWithContentsOfFile ) used in my code:
Code:
NSMutableDictionary *thumbnailCache;
- (void)applicationDidFinishLaunching:(UIApplication *)application {
(...)
thumbnailCache = [[NSMutableDictionary alloc] init];
(...)
}
+ (UIImage*)thumbnailImage:(NSString*)fileName
{
UIImage *thumbnail = [thumbnailCache objectForKey:fileName];
if (nil == thumbnail)
{
thumbnail = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:fileName ofType:@"png"]];
[thumbnailCache setObject:thumbnail forKey:fileName];
NSLog(@"add image:%@",fileName);
}
return thumbnail;
}
+ (void) removeCachedImages
{
NSLog(@"removeCachedImages:%d",[thumbnailCache count]);
[thumbnailCache removeAllObjects];
}
When initializing my UIViewController, I create the UIImageView and init it:
Code:
- (id) init {
self = [super init];
m_contentView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
self.view=m_contentView;
[m_contentView release];
for (int i=0;i<NB_BKG;i++)
{
m_bkg[i]=[[UIImageView alloc] initWithFrame:CGRectMake(0.0, 0.0, 480.0, 320.0)];
[m_contentView addSubview:m_bkg[i]];
[m_bkg[i] setImage:[TestViewCtrlAppDelegate thumbnailImage:[NSString stringWithFormat:@"test%02d",i]]];
}
return self;
}
and here is the code to release my view :
Code:
- (void)dealloc {
for (int i=0;i<NB_BKG;i++)
[m_bkg[i] release];
[TestViewCtrlAppDelegate removeCachedImages];
[super dealloc];
}
I can't understand where I missed something.
When running the project in Simulator with performance tool (object allocation) memory is well released.
But on device, memory is not released at all.
Please help me.
Thanks in advance.
Best regards,
Alx