开发者

problem with memory space in objective c

开发者 https://www.devze.com 2023-02-28 20:12 出处:网络
in my app i\'ve a tab bar with 2 navigation controller, each navigation controller has a button that open another view by push.

in my app i've a tab bar with 2 navigation controller, each navigation controller has a button that open another view by push.

I do this operation making an autorelease of the new view.

Seeing Instruments, i've noticed that when i click a button to go to next view, the memory increse, but coming back remains similar, is it normal?

The view contains only label and 1 background image, all connected by IBoutlet, all deallocated in dealloc.

For example, pressing first button and o开发者_StackOverflow社区pening first view memory 1.05 MB -> 1.78 MB, coming back 1.78 -> 1.65, then pressing again it will be constant.

Ideas?


You should implement viewDidUnload and nil the IBOutlet properties. See the UIViewController documentation.

It is possible that the background image is cached, hence the one time memory increase.


Are you loading the image with [UIImage imageNamed:@"image_file_name.jpg"] ? If so, that image is cached in memory so if you load the image again and again you won't have to read it back in from disk and recreate the underlying NSData object.

Try loading the image with [UIImage imageWithContentsOfFile:@"image_file_name.jpg"]. That method won't cache the image in memory so when you nil the image in your viewDidUnload method, all the memory will be recovered quickly.

0

精彩评论

暂无评论...
验证码 换一张
取 消