Ok thanks! So if I enable the garbage collection I just have to code and leave ALL memory management to xcode?
I grew up. Using the Garbage Collector is a revelation. No more stupid, almost impossible to track down memory leaks.
gnasher, you made a mistake. If you enable Garbage Collection at the project level to required, then all Core Foundation objects are allocated by the Garbage Collector, so it knows how to release them.
Does GC have any performance impact on a program?
Thanks Lee. Now just to confirm something from that article, you can still use retain and release commands within a GC environment if you need to for a certain object. Is that correct?
The Documentation said:If you use garbage collection, the methods that are used to implement the manual reference counting system (retain, release, dealloc, autorelease, and retainCount) have no effectthe Objective-C messenger short circuits their dispatch.
Sorry this is a stupid question, but am I doing the memory management right here?
//
// CountController.m
// StringCounter
//
// Created by Samuli Lehtonen on 1.6.2010.
// Copyright 2010 Test. All rights reserved.
//
#import "CountController.h"
@implementation CountController
-(IBAction)countString:(id)sender
{
NSString * textViewString = [[NSString alloc] init];
textViewString = [textView stringValue];
NSString * string = [[NSString alloc] initWithFormat:@"'%@' has %d characters.",textViewString,[textViewString length] ];
[textViewString release];
[labelView setStringValue:string];
[string release];
}
@end
Sorry I was meant to put the code in.. So am I doing the memory management right in this code?
Code:// // CountController.m // StringCounter // // Created by Samuli Lehtonen on 1.6.2010. // Copyright 2010 Test. All rights reserved. // #import "CountController.h" @implementation CountController -(IBAction)countString:(id)sender { NSString * textViewString = [[NSString alloc] init]; textViewString = [textView stringValue]; NSString * string = [[NSString alloc] initWithFormat:@"'%@' has %d characters.",textViewString,[textViewString length] ]; [textViewString release]; [labelView setStringValue:string]; [string release]; } @end
So I do NSString textViewString = [textView stringValue]; ?
I don't have to release textViewString at all if not why?
NSString * string = [[NSString alloc] initWithFormat:@"'%@' has %d characters.",textViewString,[textViewString length] ];
NSString * string = [NSString initWithFormat:@"'%@' has %d characters.",textViewString,[textViewString length] ];