Memory not being released right even dealloc metho

2019-08-03 17:32发布

What am I doing is I am creating lots of UIView in the background and keep them in a NSMutableArray to use later. But when I dismiss the view controller I check the memory in Xcode and it seems some of memory not being released. I checked; view controller is being deallocated.

Check please: enter image description here

This happend after several showing and dismissing the view controller. Some of them is being released but not all. Thanks.

3条回答
时光不老,我们不散
2楼-- · 2019-08-03 17:51

In dealloc method release all views that you have in the array.

called the below method in your controller dealloc method

- (void)releaseViewArray
{
// Releasing views in the array 
    for (UIView *view in _viewArray) {
        [view release];
    }
// Releasing the array that holding the views
  [_viewArray release];
}
查看更多
何必那么认真
3楼-- · 2019-08-03 17:59

I suppose you use arc, so it might be useful to explicitly release this in dealloc.

-(void)dealloc {
    for(UIView *vw in self.arrayOfViews) {
        vw = nil;
    }
    self.arrayOfViews = nil;
}

Using dealloc is a bit like the old days (pre-arc), but it will help you manage memory better. !important! --> NEVER call [super dealloc]; when using arc!

查看更多
走好不送
4楼-- · 2019-08-03 18:05

Uncheck Enable Zombie Objects option under Edit Scheme. And try again.

A zombie is an object that has been deallocated, but references to it still exist and messages are still being sent to it

I think this link has more info for you What is NSZombie?

查看更多
登录 后发表回答