Amazon.com Widgets Program 7.6 - Concept Question
Welcome, Guest. Please login or register.
Did you miss your activation email?
April 24, 2014, 01:08:57 AM
Home Help Search chat Login Register 
News: Read this please.The Great Kangaroo Escape Looking for reviews of the 4th ed on Amazon!   Twitter:  @skochan
                     

+ Official Forum for Programming in Objective-C (the iPhone Programming Language) - Stephen Kochan
|-+ Old Stuff
| |-+ Program Examples
| | |-+ Chapter 7
| | | |-+ Program 7.6 - Concept Question
Pages: [1] Go Down
Print
Author Topic: Program 7.6 - Concept Question (Read 1683 times)
Neil
Newbie
*
Posts: 5


Email




on: May 11, 2009, 04:33:41 AM

Hi

I'm was working through example 7.6 and was wondering why the fraction in sum2 is never released.  I think I figured it out but wanted to make sure I was understanding the concepts.

So the code I was struggling with was:

sum2 = [sum add: aFraction];
[sum release];
sum = sum2;

I originally thought that when sum2 is assigned to the result of [sum add: aFraction] that this created one copy of the object that is the result of add: (in sum2), and then when sum is assigned to the value of sum2, it creates a second copy of that object. 

But now I think I see that there is only ever one object created as the result of add:.  And then differet variables are assigned to have its value.  By executing [sum release] after the for loop, the single object that underlies sum and sum2 is released.

Is that right, or am I still misunderstanding what's going on?  If I'm getting it right, does that mean the final object releases outside the for loop could release aFraction and sum2 and have the same effect?

Thanks
Logged
skochan
Administrator
Hero Member
*****
Posts: 3114







Reply #1 on: May 11, 2009, 04:56:47 AM

Neil,

This topic has been extensively discussed.  Please look here:

http://classroomm.com/objective-c/index.php?topic=56.0

Cheers,

Steve Kochan
Logged
Neil
Newbie
*
Posts: 5


Email




Reply #2 on: May 12, 2009, 04:01:19 AM

Well that was stupid of me.  Sorry, I'm still figuring out where in the forums different things reside.

Neil
Logged
skochan
Administrator
Hero Member
*****
Posts: 3114







Reply #3 on: May 12, 2009, 04:42:04 AM

Neil,

Not a problem.   Wink

Cheers,

Steve Kochan
Logged
Pages: [1] Go Up
Print
Jump to:



Login with username, password and session length

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Entire forum contents (c) 2009 classroomM.com. All rights reserved.