Question on retain counts.


okay, i'm steadily working through aaron hilleglasses brilliant book on cocoa , have completed character count program , works.
thing though, i'm quite keen not rely on garbage collection , not sure if i've understood retaining , releasing properly.

initially, thought should ask release typedtext , result , program worked first time , hung. right in thinking nsstring objects dealt nsautorelease pool? other thing i'm not quite sure how retain counts relate ibactions , iboutlets.

grateful hear people thoughts , clear own in process. :)

code:
#import "countcontroller.h"      @implementation countcontroller    - (ibaction)count:(id)sender  {	  	nsstring *typedtext = [textfield stringvalue];  	nsstring *result = [[nsstring alloc]initwithformat:@"the number of characters in sentence %d",[typedtext length]];  	[countresult setstringvalue:result];  }  @end  
 

you can user method retaincount check retain count of object.

informal rule of apple api whenever object method not started init , autoreleased object.

in case [textfield stringvalue] returns autoreleased object. , after set stringvalue can release object created.
 


Forums Macs Mac Programming


  • iPhone
  • Mac OS & System Software
  • iPad
  • Apple Watch
  • Notebooks
  • iTunes
  • Apple ID
  • iCloud
  • Desktop Computers
  • Apple Music
  • Professional Applications
  • iPod
  • iWork
  • Apple TV
  • iLife
  • Wireless

Comments

Popular posts from this blog

Upgrade Eligibility?

need help with itunes 7.7

How to change Apple IDs on iPhones