2011-09-10 4 views
1

나는 수업 시간에이 방법을 코딩 한 :반환 된 개체를 해제하는 방법?

- (NSMutableDictionary *)fetch { 
    NSMutableDictionary *ret = [[NSMutableDictionary alloc] init]; 

    // filling ret with some data here 

    return ret; 
} 

올바른 릴리스없이 NSMUtableDictionary 객체를 반환하는 방법이 있나요? 돕는

들으,

스테판

+1

작은 힌트 : 다음 iOS 버전에는 더 이상 메모리를 관리 할 필요가없는 기능이 있습니다. ;-) –

+0

와우 매우 좋을 것입니다! – Steve

+1

'[NSMutableDictionary dictionary]'를 이미 자동으로 리사이징했기 때문에 대신 사용하십시오. –

답변

3

다음을 수행하십시오

- (NSMutableDictionary *)fetch { 
    NSMutableDictionary *ret = [[NSMutableDictionary alloc] init]; 
     // filling ret with some data here 
    return [ret autorelease]; 
} 

보다 약 autorelease ING 내용 this Apple document called Memory Management Programming Guide를 참조하십시오. 이

- (NSMutableDictionary *)fetch { 
    NSMutableDictionary *ret = [[NSMutableDictionary alloc] init]; 

    // filling ret with some data here 

    return [ret autorelease]; 
} 
2

사용은 오토 릴리즈 풀에 목적을두고 릴리스가 반환 된 이후 후라고합니다.

관련 문제