Will a Core Data NSInMemoryStoreType store store the entire graph in memory and therefore be severely constrained by system memory?

StackOverflow https://stackoverflow.com/questions/22168913

Question

This might seem like an obvious question, but my Googling hasn't given me a definitive response - obviously the idea of a Core Data NSInMemoryStoreType store is to store the entire graph in memory so it would seem logical to assume that this is going to place a severe constraint on the number of objects which can be stored at any one time - is this the case? Or does this store implement some kind of intelligent disk caching method to overcome this? (And if anyone has any anecdotal evidence of the kind of capacity this gives on iOS devices, preferably iPhone 4S upwards, that would also be welcome).

Was it helpful?

Solution

Given that there is an alternative, NSBinaryStoreType, where the data is documented to be stored on disk, and given the name, I would say it is safe to assume that NSInMemoryStoreType is strictly in-memory.

This Apple doc says that there is "No backing required" for an in-memory store, but does not explicitly say that none is ever used. It also notes that SQLite "does not require that the entire object graph reside in memory", implying that some other type of store does, but again it is not explicit.

See this thread where Bill Bumgarner, presumably the Bill Bumgarner that manages the iOS runtime team, talks about how you might use this type of store.

As for the limit, some answers are in ios app maximum memory budget, but you should think about the effect your program will have on the user's overall experience. If you claim all the RAM then iOS will kill their other processes, resulting in loss of context as they switch back and forth. Also iOS will kill your app any time they switch away to do Twitter or email, if it was using all the RAM. So try to stay in the low tens of megabytes, regardless of how much is apparently available, unless your app is so truly amazing that nobody would ever switch away.

OTHER TIPS

It stores everything in memory. You are right, it limits severely the amount of data that you can hold. It is up to the developer to decide when this is appropriate and when it isn't.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top