Amazon.com Widgets Return Assignment Question
Welcome, Guest. Please login or register.
Did you miss your activation email?
June 19, 2013, 03:03:52 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
| |-+  Chapter Study
| | |-+  Chapter 17 - Memory Management
| | | |-+  Return Assignment Question
Pages: [1]   Go Down
Print
Author Topic: Return Assignment Question  (Read 606 times)
jonthornham
Full Member
***
Posts: 169



WWW Email




« on: September 22, 2009, 07:06:09 PM »

I am going through Chapter 17 and watching the inheritance webcast and have a question.

Is the following:

Code: (Objective-C)
Fraction *myFrac = [[Fraction alloc] init];
Fraction *myFrac2;

[myFrac setTo:1 over: 8];

myFrac = myFrac2; //These reference the same place in memory.

equivalent to a returned Fraction? For example if a Fraction called answer from the Fraction add method is returned to result which is not allocated and initialized.

Since setting myFrac = myFrac2 does not increase the reference count a release of myFrac2 would release myFrac. I think this is the same for a returned Fraction I am just making sure.

Thanks,

Jon
Logged

Jon Thornham
skochan
Administrator
Hero Member
*****
Posts: 3109







« Reply #1 on: September 22, 2009, 07:16:59 PM »

Jon,

Yes, it's the same principle as the Program 7.5/7.6 discussion.  However, your assignment is reversed, and should be:

Code: (Objective-C)
myFrac2 = myFrac;        //These reference the same place in memory.

Cheers,

Steve Kochan
Logged
jonthornham
Full Member
***
Posts: 169



WWW Email




« Reply #2 on: September 22, 2009, 08:07:19 PM »

Thanks. That clear up a lot about return.

Take care,

Jon
Logged

Jon Thornham
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.