views:

59

answers:

3

Hey guys,

Let's put you this in context ;)

Suppose you have a tableview that you can refresh. Would you keep the activityAnimator in memory or re-create it every time you click on refresh ... ?

I know this could sound pretty obvious, it seems pretty clear that in the first case you get to speed up your app and in the other case you get to have more free memory space ...

But I was wondering whether one of the two was closer to "Apple standards" ...

Which one is more important ? CPU use or memory use ?

And don't tell me it depends on what I need to do :D

Cheers,

Gauthier

A: 

I don't think that's exist an "Apple standards".

However I think that the best way is to keep your object in the memory because it allows the application to increase the performance. If the application needs memory the os will call the didReceiveMemoryWarning method and you'll have to release unused object at this time.

But if you have a lot of object it should be a good idea to release some objects from time to time.

If you need more information you can see the Memory Management Programming Guide for Cocoa

Yannick L.
A: 

By "activityAnimator" I assume you mean UIActivityIndicatorView.

If that is the case, you should add the indicator via Interface Builder, and connect it to your view controller. This means if the controller is not top most, the OS can release the connected objects, including the indicator if required. It also means you don't have to create and destroy it each time you use it. Best of both worlds.

Having said that, this feels like premature optimisation. I would imagine the datasource backing your table view would take up much more memory that what a UIActivityIndicatorView will. I suggest setting up UIActivityIndicatorView in IB and use it.

freespace
I tried to add my UIActivityIndicatorView in IB but it just doesn't let me do it ... in IB I have a window with a nav controller and a root view controller. I added my tableView in my rootViewController but each time I try to add my indicator above my tableView it replaces my tableView and I only got my spinner...The problem is that I want my spinner to be on top of my tableView ...
gotye
@gotye Your table view should be a sibling of a UIView, and the activity indicator should also be a sibling of the same UIView. So make a new UIView, connect that to your controller's view IBOutlet, then add to it a table view and an activity spinner. See IB tutorials if this continues to elude you.
freespace
Thanks a lot ;)
gotye
A: 

Make a method that will create and return the activityAnimator. It should check if its nil and if it is create it. If not just return the existing. Then you can persist it and only release it on dealloc of that viewController or if didRecieveMemoryWarning. Then when ever you need to use it instead of referencing the class' reference call your method to make sure the reference is instianted. That way you have the best performance, but don't run afoul of memory issues.

jamone
The view controller is actually my root view controller of my navigation controller ... Will the dealloc method of my root view controller be called when I push a new view ?
gotye
I don't think it will. However since it will always release it (if you allow it) when it runs out of memory I'd stop worrying about it. Like @freespace said. The memory footprint of the UIActivityIndicatorView is likely to be such a small fraction of what your tableView's datasource is I wouldn't worry much about it. Choose any one of the methods suggested here. It will work fine.
jamone
Okay, I think I got it ! Cheers
gotye