Memory Management In iPhone

2019-09-03 16:26发布

I have an iPad App which shows a whole load of information and related images. For instance: I can access to the section “Events”, from which I can choose one. Every single one has different dates or side events. Once I choose the side event, I charge some small views, which contain the title of the news; a small image as a preview and a short text in a ViewController (which has a ScrollView). This previews can be a lot. There are no leaks due to my code (I analized with Instruments and the only ones I can find are due to NSXMLParser bug), but I have noticed that the live bytes don’t slow down, ever, they only grow. Every time I have to update the content of the ScrollView I take care of inserting the following code:

if ( bannerVideo ) { 
  [banner release]; 
  banner = nil; 
}

Do you by any chance know what could be the reason for such a constant growth?

1条回答
Rolldiameter
2楼-- · 2019-09-03 17:02

SOLVED

I added the ViewController "bannerVideo" as a subview to the main ViewController. This causes the retainCount to increase by one. So, when I asked for a new view:

if ( something ) {
  [[bannerVideo view] removeFromSuperview];
  [bannerVideo release];
  bannerVideo = nil;
}

Yes, the main access to the heap area for bannerVideo was released, but it was still retained by the main ViewController View.

查看更多
登录 后发表回答