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

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

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

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 04-17-2011, 01:06 PM   #1 (permalink)
Registered Member
 
Join Date: Mar 2011
Posts: 35
Kenenth is on a distinguished road
Default Switching Views Lag and Memory Leak?

I am creating an app that has 4 views. A homepage, and on this homepage there are 3 buttons, Each goes to one of the remaining three views(a "Play Game" view, a "How to play" view, and a "Settings" view). On the homepage, when I click the buttons that leads to "Settings" view or "How to play" view, The transition is fine, and there is no lag. But, when I click the button that leads to the "Play Game" view, there is lag for 2-3 seconds, and then it goes to the view, and gives me a "Warning: Memory Level=1" warning. I do not know why this is. Could it be that my "Play Game" view has to many things on it? I have 6 buttons, 3 UIImageViews, 4 UILabels, and a UISlider. If this is the problem, could someone please tell me how to fix it without having to take out any of these items? Or if this is not the case, I have provided the Code for Switching Views to PlayGameViewController and the code for the viewDidLoad.

ViewDidLoad:
Code:
-(void)viewDidLoad {

    gameState = KGameStateBegin;
/*
NSString *path = [[NSBundle mainBundle] pathForResource:@"GloriousMorning" ofType:@"mp3"];
AVAudioPlayer *theAudio=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
//float effects_Volume = [[NSUserDefaults standardUserDefaults] floatForKey:@"effectsVolume"];
//theAudio.volume = effects_Volume;
[theAudio play];
*/	
	
	BtnPause.hidden = 1;
	
[super viewDidLoad];
}
Yea I know, half of it is commented out, because I am not using it Currently.
And here it is for the Switching Views code:
Code:
-(IBAction)goToPlayGame:(id)sender {
	
	PlayGameViewController *view = [[PlayGameViewController alloc] initWithNibName:@"PlayGameViewController" bundle:nil];
     
	
	[UIView beginAnimations:@"Flipview" context:nil];
	[UIView setAnimationDuration:2];
	[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
	[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft 
						   forView:self.view cache:YES];
	[self.view addSubview:view.view];
	
	[UIView commitAnimations];
}
I am pretty sure there is a memory leak in the code above.(If someone could tell me how to fix it that would be great!)

Thanks a bunch!
Kenenth is offline   Reply With Quote
Old 04-17-2011, 01:09 PM   #2 (permalink)
Just helping out.
 
Domele's Avatar
 
Join Date: Feb 2011
Posts: 2,565
Domele is on a distinguished road
Default

You need to release your PlayGameViewController after you add it to the view. The view retains it for you so you can release your reference to it afterwards. And try to be more descriptive with your pointer names.
Domele is offline   Reply With Quote
Old 04-17-2011, 02:44 PM   #3 (permalink)
Registered Member
 
Join Date: Feb 2010
Posts: 75
matt62king is on a distinguished road
Default

You also need to release your audio player.
__________________
My Twitter -- @matt62king
matt62king is offline   Reply With Quote
Old 04-17-2011, 03:43 PM   #4 (permalink)
Just helping out.
 
Domele's Avatar
 
Join Date: Feb 2011
Posts: 2,565
Domele is on a distinguished road
Default

Quote:
You also need to release your audio player.
It's commented out. The whole block from NSString *path to [theAudio play] is commented out.
Domele is offline   Reply With Quote
Old 04-17-2011, 06:42 PM   #5 (permalink)
Registered Member
 
Join Date: Dec 2008
Location: UK
Posts: 1,896
harrytheshark is on a distinguished road
Default

Quote:
Originally Posted by Domele View Post
You need to release your PlayGameViewController after you add it to the view. The view retains it for you so you can release your reference to it afterwards. And try to be more descriptive with your pointer names.
The superview only retains the view controller's view, not the view controller. The view controller must be retained as well.
harrytheshark is offline   Reply With Quote
Old 04-17-2011, 06:53 PM   #6 (permalink)
Registered Member
 
Join Date: Mar 2011
Posts: 35
Kenenth is on a distinguished road
Default

Ok thanks. Sorry Im 3 weeks new to xcode, so how would I do this?
Kenenth is offline   Reply With Quote
Old 04-17-2011, 07:04 PM   #7 (permalink)
Registered Member
 
Join Date: Feb 2011
Posts: 633
ilmman is on a distinguished road
Default

Quote:
Originally Posted by Kenenth View Post
Ok thanks. Sorry Im 3 weeks new to xcode, so how would I do this?
[playviewcontroller release]; ???????? after u load it? AM I RIGHT>? AM I RIGHT?
ilmman is online now   Reply With Quote
Old 04-18-2011, 04:02 AM   #8 (permalink)
Registered Member
 
Join Date: Dec 2008
Location: UK
Posts: 1,896
harrytheshark is on a distinguished road
Default

The playViewController needs to be retained somewhere, otherwise it'll crash - try using a property.

Also, you only need to use one question mark.
harrytheshark is offline   Reply With Quote
Reply

Bookmarks

Tags
lag, memory leak, switching views

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 358
14 members and 344 guests
dansparrow, dre, ilmman, LezB44, lorrettaui53, Nobbsy, Objective Zero, oztemel, pbart, samdanielblr, shagor012, sledzeppelin, thephotographer, Trickphotostudios
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,663
Threads: 94,119
Posts: 402,896
Top Poster: BrianSlick (7,990)
Welcome to our newest member, LezB44
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 01:47 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0