NSMutableArray destruction

前端 未结 5 2092
广开言路
广开言路 2021-02-02 16:48

I have an array NSMutableArray with happy objects. These objects viciously turn on (leak) me whenever I try to clear the array of all the objects and repopulate it.

5条回答
  •  忘了有多久
    2021-02-02 17:04

    Are you referring to the objects in the array leaking?

    How are you adding objects to the array? The array will retain them, so you need to autorelease or release them after you've added them to the array. Otherwise after the array is released the objects will still be retained (leaked).

    MyEvent *event = [[MyEvent alloc] initWithEventInfo:info];
    [self.eventList addObject:event];
    [event release];
    
    MyEvent *otherEvent = [[[MyEvent alloc] initWithEventInfo:otherInfo] autorelease];
    [self.eventList addObject:otherEvent];
    

提交回复
热议问题