January 23, 2018, 08:57:43 AM
Welcome,
Guest
. Please
login
or
register
.
Did you miss your
activation email?
1 Hour
1 Day
1 Week
1 Month
Forever
Login with username, password and session length
Read this please.
♦
The Great Kangaroo Escape
♦
Looking for reviews of the 4th ed on Amazon!
♦
Twitter:
@skochan
Home
Help
Search
Login
Register
Chat
Official Forum for Programming in Objective-C (the iPhone Programming Language) - Stephen Kochan
>
Old Stuff
>
Answers to Exercises
>
Chapter 15
>
exercise 15.7 weirdness
Pages: [
1
]
Go Down
« previous
next »
Print
Author
Topic: exercise 15.7 weirdness (Read 1361 times)
Robot-Scott
Jr. Member
Posts: 52
exercise 15.7 weirdness
«
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
Re: exercise 15.7 weirdness
«
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
Re: exercise 15.7 weirdness
«
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.
Logged
"Think globally, act within local variable scope."
webwrx
Newbie
Posts: 41
Re: exercise 15.7 weirdness
«
Reply #3 on:
August 23, 2009, 01:25:27 PM »
Quote from: skochan on July 19, 2009, 01:15:04 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
« previous
next »
Jump to:
Please select a destination:
-----------------------------
Programming in Objective-C, 5th edition
-----------------------------
=> General Discussions
=> Exercises
-----------------------------
Programming in Objective-C, 4th edition
-----------------------------
=> General Discussion
=> Exercises
===> Chapter 2
===> Chapter 3
===> Chapter 4
===> Chapter 5
===> Chapter 6
===> Chapter 7
===> Chapter 8
===> Chapter 9
===> Chapter 10
===> Chapter 11
===> Chapter 12
===> Chapter 13
===> Chapter 14
===> Chapter 15
===> Chapter 16
===> Chapter 17
===> Chapter 18
===> Chapter 19
===> Chapter 20
===> Chapter 21
=> Chapter 2
=> Chapter 3
=> Chapter 4
=> Chapter 5
=> Chapter 6
=> Chapter 7
=> Chapter 8
=> Chapter 9
=> Chapter 10
=> Chapter 11
=> Chapter 12
=> Chapter 13
=> Chapter 14
=> Chapter 15
=> Chapter 16
=> Chapter 17
=> Chapter 18
=> Chapter 19
=> Chapter 20
=> Chapter 21
=> Errata
===> 1st Printing
===> 2nd Printing
-----------------------------
Members' Corner
-----------------------------
=> Look What I'm Doing...
-----------------------------
Study Group
-----------------------------
=> Objective-C Quizzes
===> Comprehensive Quiz
===> Chapter 1 - Introduction
===> Chapter 2 - Programming in Objective-C
===> Chapter 3 - Classes, Objects, and Methods
===> Chapter 4 - Data Types and Expressions
===> Chapter 5 - Program Looping
===> Chapter 6 - Making Decisions
===> Chapter 7 - More on Classes
===> Chapter 8 - Inheritance
===> Chapter 9 - Polymorphism, Dynamic Typing, and Dynamic Binding
===> Chapter 10 - More on Variables and Data Types
===> Chapter 11 - Categories and Protocols
===> Chapter 12 - The Preprocessor
===> Chapter 15 - Numbers, Strings & Collections
===> Chapter 17 - Memory Management
-----------------------------
iOS Programming
-----------------------------
=> General Questions
-----------------------------
Programming in C, 3rd ed. (Stephen Kochan)
-----------------------------
=> Programming in C webcasts?
=> Answers to Odd-Numbered Exercises
=> Questions and Help
-----------------------------
Old Stuff
-----------------------------
=> Errata, Answers to Exercises, Code, etc.
=> Shared Code Library
=> Welcome
=> News
=> Errata
===> 1st Printing
===> 2nd printing
=> Newbie Corner
=> Chapter Study
===> Chapter 2 - Programming in Objective-C
===> Chapter 3 - Classes, Objects, and Methods
===> Chapter 4 - Data Types and Expressions
===> Chapter 5 - Program Looping
===> Chapter 6 - Making Decisions
===> Chapter 7 - More on Classes
===> Chapter 8 - Inheritance
===> Chapter 9 - Polymorphism, Dynamic Typing, and Dynamic Binding
===> Chapter 10 - More on Variables and Data Types
===> Chapter 11 - Categories and Protocols
===> Chapter 12 - The Preprocessor
===> Chapter 13 - Underlying C Language Features
===> Chapter 15 - Numbers, Strings, and Collections
===> Chapter 16 - Working with Files
===> Chapter 17 - Memory Management
===> Chapter 18 - Copying Objects
===> Chapter 19 - Archiving
===> Chapter 21 - Writing iPhone Applications
=> Answers to Exercises
===> Chapter 2
===> Chapter 3
===> Chapter 4
===> Chapter 5
===> Chapter 6
===> Chapter 7
===> Chapter 8
===> Chapter 9
===> Chapter 10
===> Chapter 11
===> Chapter 12
===> Chapter 13
===> Chapter 15
===> Chapter 16
===> Chapter 17
===> Chapter 18
===> Chapter 19
===> Chapter 21
=> General Discussion
=> Program Examples
===> Chapter 2
===> Chapter 3
===> Chapter 4
===> Chapter 5
===> Chapter 6
===> Chapter 7
===> Chapter 8
===> Chapter 9
===> Chapter 10
===> Chapter 11
===> Chapter 12
===> Chapter 13
===> Chapter 15
===> Chapter 16
===> Chapter 17
===> Chapter 18
===> Chapter 19
===> Chapter 21
=> XCode 4 Help
=> Suggestions
=> Help!!!
=> Fraction Calculator Available from the App Store
=> Resources
=> Errata
===> 1st & 2nd printings
===> 3rd & 4th printings
===> 5th printing
===> Current Errata
=> Suggestion Box
=> Tips & Tricks
=> Part 3
===> Welcome to the Class
===> Special Announcements
===> Assignments
=> Parts 1 and 2
===> Welcome to the Class
===> Questions and Discussion
===> SPECIAL ANNOUNCEMENTS
===> Assignments
===> Chapter 4, Exercise 7
===> Suggestions
=> Webcast Series Part I, Sept. 1 - 24
===> Welcome
===> SPECIAL ANNOUNCEMENTS
===> Questions and Discussion
===> Assignments
===> Chapter 4, Exercise 7
===> Chapter 6, Exercise 4
===> Suggestions
=> Webcast Series Part II, Oct. 1 - 27
===> Welcome
===> SPECIAL ANNOUNCEMENTS
===> Questions and Discussion
===> Assignments
===> Example using hasPrefix: and hasSufix:
===> Suggestions
=> Objective-C Workshop Aug 11 - 13
=> Webcast Series Part I, Oct. 29 - Dec. 1
===> Welcome
===> SPECIAL ANNOUNCEMENTS
===> Assignments
===> Chapter 4, Exercise 7
===> Chapter 6, Exercise 4
===> Suggestions
=> Webcast Series Part II, Jan 5 - 28
===> Welcome
===> SPECIAL ANNOUNCEMENTS
===> Assignments
===> Jan 7th Solutions
Loading...