Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum

View Single Post
Old 06-02-2009, 04:59 AM   #1 (permalink)
Alx
New Member
 
Join Date: Jan 2009
Posts: 11
Lightbulb Not able to release UIViewController memory

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
Alx is offline   Reply With Quote
 

» Advertisements
» Online Users: 753
17 members and 736 guests
AppAnnex, carpi, dfvdan, Domele, Gurpartap Singh, her-ur, juggler, melmoup, nathanrose, nidie, Pavel Volobuev, PetarPM, phackdat, sneaky, Tambourin, V_SC&, Xaron
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,836
Threads: 89,209
Posts: 380,643
Top Poster: BrianSlick (7,129)
Welcome to our newest member, abbylowin
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 03:35 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.