Official Forum for Programming in Objective-C (the iPhone Programming Language) - Stephen Kochan
January 23, 2018, 08:54:47 AM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
 
   Home   Help Search Login Register Chat  
Pages: [1]   Go Down
  Print  
Author Topic: exercise 15.7 weirdness  (Read 1360 times)
Robot-Scott
Jr. Member
**
Posts: 52



« on: July 19, 2009, 11:55:57 AM »

Man, this is a hard chapter (at least for me).

I haven't even gotten to the part about getting the sum of fractions but I have modified the Fraction class to be an object that holds NSNumbers and I created a FractionArray class to hold collections of Fractions.  So, I tested these parts by creating some fractions, adding them to the array, and then printing the array.  I then release the memory of the fractions and the fractions' array.  However, I keep getting a signal 11 when I include the release of memory for the array.  When I edit out that line I get a signal 0 after the program runs.  I don't know how to use the debugger really, but I saw that it had highlighted the [pool drain] call so I figure it has to do with some conflict between the array and the autorealease pool.  I don't get it because the program looks exactly like the Address Book program with the substitution of fractions for address cards.

I included the project as a zip file.
Logged

"Think globally, act within local variable scope."
skochan
Administrator
Hero Member
*****
Posts: 3114



« Reply #1 on: July 19, 2009, 01:15:04 PM »

You shouldn't be releasing your numerator and denominator instance variables in your dealloc method in your Fraction class.  You're storing number objects there that are created by Foundation methods.  As noted in the text, objects created by Foundation methods other than alloc, copy, or new, are automatically added to the autorelease pool.  So they are being over-released.

Cheers,

Steve Kochan
Logged
Robot-Scott
Jr. Member
**
Posts: 52



« Reply #2 on: July 19, 2009, 06:10:18 PM »

As always, thank you!

I think I'm going to print that rule out about Foundation memory management and post it on my wall. Cheesy
Logged

"Think globally, act within local variable scope."
webwrx
Newbie
*
Posts: 41


« Reply #3 on: August 23, 2009, 01:25:27 PM »

As noted in the text, objects created by Foundation methods other than alloc, copy, or new, are automatically added to the autorelease pool.


When you say 'copy', do you mean in the context of @property (copy,...) ?

Ben
Logged
Pages: [1]   Go Up
  Print  
 
Jump to:  

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 ゥ 2009 classroomM.com. All rights reserved.