views:

32

answers:

2

Hello - I have a tab bar in may app that controls 5 different views. To ease memory issues, I would like to release a large image when leaving the tab then reload it when that tab is selected again.

Any ideas?

I am looking for a delegate method that would activate when a user selects a different tab

A: 

I think it depends on how frequenly user will access the view that have the image. If it is too big and take a lot of time to load, I can suggest you a workaround:

You store another small copy of that image in memory, when you need to load the big image, show the small image first and then when the big image is loaded, replace the small one. So, you can save the memory and let the user less waiting in the blank screen

If it doesn't take time to load and is not frequently accessed, you can go ahead and release from the memory

vodkhang
the image doesnt take long to load, but it takes up the entire screen and three of my views have similar full screen images. The image file itself will remain in memory, but I just want to remove the imageView.image so I'm not wasting memory displaying a large image that isn't being viewed. The iPad version works fine this way, but for the iPhone version I am having a lot of crashes due using too much memory.
Brodie
So, I think that you can just release it. And I think if you dealocate the imageView.image, you remove the image file as well, right? Anyway, if it doesn't take time to load, you can release it to save memory
vodkhang
but my question is how to I activate the method that will release it. I cant find a delegate method that will activate when a view is selected/deselected
Brodie
But you didn't say anything about that in the question. I misunderstood that you want to ask if you should release the image or not? Now, your question is when a view is selected/deselected, some methods are called and you can release your image there, right?
vodkhang
http://developer.apple.com/iphone/library/documentation/uikit/reference/UITabBarDelegate_Protocol/Reference/Reference.html#//apple_ref/occ/intfm/UITabBarDelegate/tabBar:didSelectItem:This link should be what you are asking for
vodkhang
I'm sorry I was not more clear. I have already looked at those and from reading them I'm not sure which applies to my situation. DidSelectItem sounds close but I'm still not sire how to properly implement it
Brodie
Try it and if you still have problem, you can ask again
vodkhang
A: 

used viewWillDisappear and viewWillAppear to fix this

Brodie