NSMutableArray memory management

后端 未结 5 1051
情歌与酒
情歌与酒 2020-12-09 08:48
NSMutableArray *a1 = [[NSMutableArray alloc] init];
NSMutableArray *a2 = [NSMutableArray array];

TempObj *obj = [[TempObj alloc] init]; //assume this line is repeat         


        
5条回答
  •  旧时难觅i
    2020-12-09 09:05

    The basic thing to remember is this: You must balance every call to "init", "retain" or "copy" with a corresponding call to "release" or "autorelease". That's really all that you need to know.

    In your example, a1 had a call to "init", so you need to have a "release" somewhere on it. Ditto with "obj". You didn't call "init", "retain", or "copy" on anything else, so you don't need to call "release" or "autorelease" on anything else.

提交回复
热议问题