Amazon.com Widgets Do I need to override dealloc here?
Welcome, Guest. Please login or register.
Did you miss your activation email?
July 23, 2014, 11:25:11 PM
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 18 - Copying Objects
| | | |-+ Do I need to override dealloc here?
Pages: [1] Go Down
Print
Author Topic: Do I need to override dealloc here? (Read 569 times)
dharr19
Full Member
***
Posts: 175


Email




on: September 25, 2011, 03:30:14 PM

Hi Stephen,

Don't I need to override dealloc and release name in this short program

Code: (Objective-C)
#import <Foundation/Foundation.h>
@interface test: NSObject
{
    NSString *name;
    
}
@property (nonatomic, copy) NSString *name;

@end

@implementation test

@synthesize name;

@end

int main (int argc, const char * argv[])
{

    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
    test *myTest = [[test alloc] init];
    NSMutableString *myString = [NSMutableString stringWithString:@"hello"];
    
    myTest.name = myString;
    
    [myString appendString:@"goodbye"];
    
    NSLog(@"myString = %@",myString);
    NSLog(@"name = %@",[myTest name]);
    
    [myTest release];
    [pool drain];
    return 0;
}

Any help is appreciated
Cheers
David
Logged
skochan
Administrator
Hero Member
*****
Posts: 3114







Reply #1 on: September 26, 2011, 08:22:42 AM

Yes, because you use the copy attribute on the property, you would normally want to override dealloc here to release name.

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.