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 03-25-2009, 11:25 AM   #1 (permalink)
Registered Member
 
Join Date: Mar 2009
Posts: 21
raven is on a distinguished road
Default Ivar - Retain, Assign and Release related crash

This is probably more a conceptual issues so experienced insight is welcome.

localWindow = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window = localWindow;
[localWindow release];
/* Now the following code crashes
localTBC = [[UITabBarController alloc] init];
tabBarController = localTBC;
[localTBC release];
*/
tabBarController = [[UITabBarController alloc] init]; //this works great

***
@property (nonatomic, retain) UIWindow *window;
@property (nonatomic, retain) UITabBarController *tabBarController;
***


Why does it crash when I use the commented lines for tabBarController for the following line.

tabBarController.viewControllers = theVCArray;

It crash as tabBarController has already been released in the commented code case.

I assume the retain count will be 2 due to the assign and retain on tabBarController ivar as it will be for window ivar. Why is it okay with window but not with tabBarController ?
raven is offline   Reply With Quote
Old 03-25-2009, 11:38 AM   #2 (permalink)
Pro. Game Developer
iPhone Dev SDK Supporter
 
Join Date: Feb 2009
Location: żLa Islas Hermosas?
Posts: 2,176
Kalimba is on a distinguished road
Default

Quote:
Originally Posted by raven View Post
This is probably more a conceptual issues so experienced insight is welcome.

Code:
      localWindow = [[UIWindow alloc] initWithFrame:[[UIScreen      mainScreen] bounds]];
	self.window = localWindow;
	[localWindow release];
	/*  Now the following code crashes
	localTBC = [[UITabBarController alloc] init];
	tabBarController = localTBC;
	[localTBC release];
	*/
	tabBarController = [[UITabBarController alloc] init]; //this works great
***
@property (nonatomic, retain) UIWindow *window;
@property (nonatomic, retain) UITabBarController *tabBarController;
***


Why does it crash when I use the commented lines for tabBarController for the following line.

tabBarController.viewControllers = theVCArray;

It crash as tabBarController has already been released in the commented code case.

I assume the retain count will be 2 due to the assign and retain on tabBarController ivar as it will be for window ivar. Why is it okay with window but not with tabBarController ?
It's crashing at that line because the "tabBarController" isn't pointing to anything valid, as you've released the instance you had allocated.
Code:
	tabBarController = localTBC;
should be this:
Code:
	self.tabBarController = localTBC;
Kalimba is offline   Reply With Quote
Old 03-25-2009, 12:02 PM   #3 (permalink)
Registered Member
 
Join Date: Mar 2009
Posts: 21
raven is on a distinguished road
Default

But aren't these two lines the same ?

You are using the dot notation but in both cases we are referring to the same ivar called tabBarController !
raven is offline   Reply With Quote
Old 03-25-2009, 12:22 PM   #4 (permalink)
ftm
FasterThanMonkeys.com
 
Join Date: Mar 2009
Location: Southern California
Posts: 523
ftm is on a distinguished road
Send a message via AIM to ftm
Default

Are you also doing an

@synthesize tabBarController;

in your class?

My understanding is that synthesize is what makes the created getters and setters actually do the retain and release code correctly.
__________________


Website: http://fasterthanmonkeys.com

iScore Baseball Scorekeeper Top baseball scorekeeping app for iPhone
Bug Squash Reached #1 kids game in 15+ countries including USA, now with OpenFeint
Jam Packed! Fun puzzle game for all ages
Jam Packed Christmas Holiday puzzle game!
iScore Basketball Scorekeeper Best basketball scorekeeping application
ftm is offline   Reply With Quote
Old 03-25-2009, 12:41 PM   #5 (permalink)
Registered Member
iPhone Dev SDK Supporter
 
smasher's Avatar
 
Join Date: Jul 2008
Location: San Mateo, CA (San Fran)
Posts: 3,858
smasher will become famous soon enough
Default

Quote:
Originally Posted by raven View Post
But aren't these two lines the same ?

You are using the dot notation but in both cases we are referring to the same ivar called tabBarController !
Dot notation doesn't access the ivar directly - it calls the methods tabBarController and setTabBarController. Those methods handle the reatain and release, and it's "@synthesize tabBarController;" that creates these methods.
__________________

Free Games!
smasher is offline   Reply With Quote
Reply

Bookmarks

Tags
memory management

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: 332
3 members and 329 guests
guusleijsten, Kryckter, LEARN2MAKE
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,649
Threads: 94,113
Posts: 402,880
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Anwerbl
Powered by vBadvanced CMPS v3.1.0

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