소멸자 [free] Objc

#import <stdio.h>
#import <objc/Object.h>

@interface Test : Object
-(id)init;
-(id)free;
@end

@implementation Test
- (id)init {
    id obj = [super init];
    printf("init method\n");
    return obj;
}
- (id)free {
    printf("free method\n");
    return [super free];
}
@end

int main() {
    id obj = [Test new];
    [obj free];

    return 0;
}
 
위의 코드는 메모리 할당 후 바로 해제하는 코드이다.

Share
이 글과 관련된 글
  1. [2009/11/20] 클래스 오브젝트 by 두목원숭이 (401)
  2. [2009/11/20] 클래스 메소드 by 두목원숭이 (467)
  3. [2009/11/20] 가시성[접근자] by 두목원숭이 (311)
  4. [2009/11/20] 정적 클래스 by 두목원숭이 (413)
  5. [2009/11/20] 생성자 [constructor] by 두목원숭이 (274)
Tag :

Leave Comments



T-NAVI