我在一類編碼這個方法:如何釋放返回的對象?
- (NSMutableDictionary *)fetch {
NSMutableDictionary *ret = [[NSMutableDictionary alloc] init];
// filling ret with some data here
return ret;
}
是不正確發佈此返回對象的NSMutableDictionary的方式嗎?
THX幫助,
斯特凡
我在一類編碼這個方法:如何釋放返回的對象?
- (NSMutableDictionary *)fetch {
NSMutableDictionary *ret = [[NSMutableDictionary alloc] init];
// filling ret with some data here
return ret;
}
是不正確發佈此返回對象的NSMutableDictionary的方式嗎?
THX幫助,
斯特凡
執行以下操作:
- (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];
}
自動釋放把對象變成一個自動釋放池,並釋放被稱爲已返回後後。
小提示:下一個iOS版本具有功能,因此您不必再自行管理內存。 ;-) –
哇會很好! – Steve
只需使用'[NSMutableDictionary dictionary]',因爲它已經被自動發佈。 –