2011-09-10 75 views
1

我在一類編碼這個方法:如何釋放返回的對象?

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

    // filling ret with some data here 

    return ret; 
} 

是不正確發佈此返回對象的NSMutableDictionary的方式嗎?

THX幫助,

斯特凡

+1

小提示:下一個iOS版本具有功能,因此您不必再自行管理內存。 ;-) –

+0

哇會很好! – Steve

+1

只需使用'[NSMutableDictionary dictionary]',因爲它已經被自動發佈。 –

回答

2

使用這樣

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

    // filling ret with some data here 

    return [ret autorelease]; 
} 
相關問題