iPhone memory management, a newbie question

前端 未结 3 1552
夕颜
夕颜 2021-01-07 02:51

I\'ve seen in (Apple) sample code two types of ways of allocation memory, and am not sure I understand the difference and resulting behavior.

// FAILS
NSMuta         


        
3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-07 03:06

    Please keep in mind that

    NSMutableArray *anArray = [NSMutableArray array];
    

    acts like:

    NSMutableArray *anArray1 = [[[NSMutableArray alloc] init] autorelease];
    

    So doing a release again will cause the crash as you are trying to release an autoreleased object.

    Hope this helps you.

    Thanks,

    Madhup

提交回复
热议问题