Amazon.com Widgets Program 10.1
Welcome, Guest. Please login or register.
Did you miss your activation email?
May 24, 2013, 09:17:23 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
|-+  Programming in Objective-C, 4th edition
| |-+  Chapter 10
| | |-+  Program 10.1
Pages: [1]   Go Down
Print
Author Topic: Program 10.1  (Read 575 times)
th3ub3r3x
Newbie
*
Posts: 1


Email




« on: February 08, 2012, 02:34:52 PM »

In program 10.1
Code: (Objective-C)
#import "Fraction.h"
int main (int argc, char * argv[])
{
     @autoreleasepool {
          Fraction *a, *b;
          a = [[Fraction alloc] initWith: 1 over: 3];
          b = [[Fraction alloc] initWith: 3 over: 7];
          [a print]; [b print];

          [a release];
          [b release];
      }
return 0;
}
I don't understand the purpose of the final two statements (a and b release method invocations).  I typed the program in exactly how the book did and it gives me the error
'release' is unavailable: not available in automatic reference counting mode.

Thanks for the help
Mark Johnson
Logged
dharr19
Full Member
***
Posts: 175


Email




« Reply #1 on: February 09, 2012, 01:35:02 PM »

Hi Mark,

The release statement isn't needed when using ARC.  Before Xcode 4.2, you had to manage memory taken up by objects.  When creating a new class look for the checkbox that says Use Automatic Reference Control. If you were to create program 10.1 again and uncheck that checkbox.  The program would work fine. The 10.1 program was from the previous edition and the release statements were just overlooked. If you remove them it will work fine.

Cheers
David
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.