Discussion Forums  >  Crashes, Memory Warnings

Replies: 3    Views: 146

nadthevlad
Code is Art
Profile
Posts: 1025
Reg: Jun 07, 2012
Denver
21,850
01/17/13 10:09 PM (11 years ago)

Zombie in BT_color? for David

I am using BT_color to set a variable here. _quizButtonColorCorrect = [BT_color getColorFromHexString:[BT_strings getJsonPropertyValue:self.screenData.jsonVars:@"button_color_correct":@"#000000"]]; Then calling on that variable here [_answerButton1 setBackgroundColor : _quizButtonColorCorrect]; but am getting an EXC_BAD_ACCESS on the _quizButtonColorCorrect variable. I turned on the zombie tracker and traced the stack call to BT_color.m http://dl.dropbox.com/u/2452503/zombie.jpg http://dl.dropbox.com/u/2452503/zombie2.jpg I tried changing line 81 of BT_color from this: return [UIColor colorWithRed:red green:green blue:blue alpha:alpha]; to this: return [[UIColor colorWithRed:red green:green blue:blue alpha:alpha]retain]; based on this: http://forums.macrumors.com/archive/index.php/t-1425209.html This cleared the EXC_BAD_ACCESS. One other possibility is to try changing that line to this: return [[UIColor alloc] colorWithRed:red green:green blue:blue alpha:alpha] based on that link. Am I correct in doing this? Will it cause problems later down the line? Running OSX 10.7.5 arc is turned off _quizButtonColorCorrect is nonatomic, retain
 
David @ buzztouch
buzztouch Evangelist
Profile
Posts: 6866
Reg: Jan 01, 2010
Monterey, CA
78,840
like
01/18/13 12:53 AM (11 years ago)
Hey there. Hard to say what's best in your situations but I would not change the BT_Color class unless you understand for sure why you would want or need to. Assuming your building on the existing Quiz Plugin....I'm not sure why you would create a new variable named _answerButton1 and another one named _quizButtonColorCorrect. Note the under-bar in front of the names. If you look in the quiz plugins .h file you'll see that these two instance variables (properties) are already created and named the same thing without the under-bar. answerButton1 and quizButtonColorCorrect are declared in the .h file, then created and modified in the .m file. You'll also see where they are released in the dealloc method of the .m file. It's important to release them to free up the memory they consume while the screen is in use. The color objects that is returned by the BT_Color class (when using the Class Method getColorFromHexString) is not released. This means you'll need to release any colors you create with it in your implementation. You could... 1) Use the already created properties and not your "_" properties. OR 2) Stop autoreleasing your "_" properties (if you want to use them) and release them when you're code is done with them.
 
Annonymous
Profile
01/18/13 12:50 PM (11 years ago)
Hmm. Lots of confusion on my part about the appropriate use of the underscore. In .h UIColor *quizButtonColorCorrect; ... @property (nonatomic, retain) UIColor *quizButtonColorCorrect; In .m @synthesize quizButtonColorCorrect = _quizButtonColorCorrect; ... [_quizButtonColorCorrect release]; _quizButtonColorCorrect = nil; With out making any changes to BT_color I tried self.quizButtonColorCorrect = [BT_color getColorFromHexString:[BT_strings getJsonPropertyValue:self.screenData.jsonVars:@"button_color_correct":@"#000000"]]; and [_answerButton1 setBackgroundColor : self.quizButtonColorCorrect]; without any problems. Looks like I am going to have to read up some more on ivars and properties.
 
nadthevlad
Code is Art
Profile
Posts: 1025
Reg: Jun 07, 2012
Denver
21,850
like
01/18/13 12:57 PM (11 years ago)
Last post was mine. Browser times out.
 

Login + Screen Name Required to Post

pointerLogin to participate so you can start earning points. Once you're logged in (and have a screen name entered in your profile), you can subscribe to topics, follow users, and start learning how to make apps like the pros.