Amazon.com Widgets Chapter 7: Memory Leak
Welcome, Guest. Please login or register.
Did you miss your activation email?
August 01, 2014, 06:52:58 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 7 - More on Classes
| | | |-+ Chapter 7: Memory Leak
Pages: [1] Go Down
Print
Author Topic: Chapter 7: Memory Leak (Read 1352 times)
scarubia
Newbie
*
Posts: 38


Email




on: October 28, 2011, 04:24:59 PM

3rd edition, pages 141 - 143

These pages alert to the potential for memory leaks resulting from objects created within methods. Solutions to releasing these objects are described.

Is this information still relevant under Xcode 4.2?

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







Reply #1 on: October 28, 2011, 04:41:10 PM

No, it's not relevant if using ARC.  (Don't let my editor know, but I'm attaching most of the new Chapter 7 from the 4E---not in its final format.)  Don't distribute or show around.  Smiley

Note that Program 7.6 is completely gone from the 4E.   That example always proved difficult for readers and the memory management issues related to it are no longer relevant.

Cheers,

Steve
Logged
scarubia
Newbie
*
Posts: 38


Email




Reply #2 on: October 28, 2011, 05:45:15 PM

I wasn't going to reply to this so that people would be compelled -- upon seeing your name in the reply field -- to check out the useful information and material you've shared here.

Couldn't go without expressing my gratitude however. Thank you!
Logged
skochan
Administrator
Hero Member
*****
Posts: 3114







Reply #3 on: October 28, 2011, 06:59:33 PM

Haha.  So here's a reply so my name stays on top!  Smiley

Cheers,

Steve
Logged
Learner
Newbie
*
Posts: 21


Email




Reply #4 on: November 20, 2011, 04:17:24 PM

Hey Steve, I am using your 2nd edition book and it's great!

On a similar issue, on pages 153 of the 2nd ed you write:

Quote
Because you take the Fraction that add: returns and send it a message to print, you have no way of subsequently releasing the Fraction object that add: created. This is an example of memory leakage. If you do this...each time you would be adding, or leaking, just a little bit more memory that could not directly recover. One solution to the problem is to have the print method return its receiver, which you could then release. But that seems a little roundabout. A better solution is to divide the nested messages into two separate messages, was done earlier in the program.

I am not entirely sure if this is still relevant as you were saying earlier, but how would that print message look?
Logged
skochan
Administrator
Hero Member
*****
Posts: 3114







Reply #5 on: November 21, 2011, 05:06:01 PM

No, that wouldn't be an elegant solution, as noted in the text.  You'd have the print method return an argument of type Fraction *, and it would look like this:

Code: (Objective-C)
-(Fraction *) print
{
      NSLog (@"%i/%i", numerator, denominator);
      return self;
}


Cheers,

Steve

Logged
Learner
Newbie
*
Posts: 21


Email




Reply #6 on: November 21, 2011, 09:16:43 PM

I see. So what is this 
Quote
divide the nested messages into two separate messages

Is it an elegant solution because it means you dont have to create an extra method, you can just cut up the message into two parts and then release each object?
Logged
skochan
Administrator
Hero Member
*****
Posts: 3114







Reply #7 on: November 22, 2011, 05:06:53 PM

Yes, it's better because you can get a handle on the object and subsequently release it.  Note that if using ARC that there will be no memory leak and the nested expression can be used!

Cheers,

Steve
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.