views:

25

answers:

1

I'm working on a table view that will display all of a certain type of managed object, and I'm wondering if I should be doing something to prevent faults from firing all the time when the user scrolls and I set up a new cell in the data source?

I don't know too much detail about large amounts of managed objects, (several hundred) but I understand firing a fault is resource expensive, and if every time a cell shows up I'm asking a managed object for one of its properties, should I maybe be making a separate new array in viewDidLoad with all the information necessary to show a table view cell, thus preventing the repeated faulting of managed objects?

Thanks for any help with this.

+2  A: 

There is a reason that that the introductory materials for Core Data do not spend any time on memory management. Core Data is very efficient in memory use and handles it automatically. If your app encounters low memory, Core Data will convert live objects to faults if they are not being actively accessed.

In the case of tables, if you use a fetched results controller, you won't be loading in all the managed objects in one gulp but only those whose attributes you directly access. For example, suppose you use an indexed table with thousands of alphabetized objects. When the table first loads, only the 10 or so managed objects needed to populate the visible cells are in memory. If you use the index to just to "Z", only the managed objects needed to display those few cells being displayed at once under "Z" are loaded into memory. Even if you scroll through a non-indexed table, your memory use is low as the table knows to ask for cells only for rows that actually readable.

Premature optimization is the source of all programming evil. Don't waste time and add complexity trying to prevent problems you may never have.

In the specific case of Core Data, it handles 95% of all memory issue for you. That is one of its major advantages. I seldom pay any attention to Core Data's memory use.

Instead, start with the simplest implementation. You shouldn't worry about memory use until you've tested and found a problem.

TechZen
I cannot agree with this answer more.
Marcus S. Zarra
That explains it, I really was stuck for info on memory management on core data, thanks for the tip.
Alex Gosselin