2011-09-10 8 views
1

私はクラスでこのメソッドをコード化されています:返されたオブジェクトを解放するには?

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

    // filling ret with some data here 

    return ret; 
} 

が正しいリリースせずにこのNSMUtableDictionaryオブジェクトを返す方法は何ですか?

ステファン

+1

少しヒント:次のiOSバージョンには機能がありますので、自分でメモリを管理する必要はありません。 ;-) –

+0

wow非常に素晴らしいでしょう! – Steve

+1

すでに[autoreleased]の代わりに '[NSMutableDictionary dictionary]'を代わりに使用してください。 –

答えて

3

は、次の操作を行い助けるため

Thxを、:

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

ING autoreleaseの詳細についてはは、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

使用は、自動解放プールにオブジェクトを置くとリリースは、それが返された後の後に呼び出されます。

関連する問題