开发者

iPhone NSMutableArray vs. SQLite

I have an catalog developed for iPhone that is my first app. Because of it, I have some problems with memory leaks and the app crash down when I have more than 55 photos in catalog. (I will explain when it crashs)

I already tested with Leaks Performance Tools and I successfully fixed the leaks, but my app stills crashing.

My Data class have 5 NSMutableArrays. 1 have 50 UIImage elements for Portrait. The second have 25 UIImage elements for Landscap (catalog uses 2 portrait in 1 landscape image). Other have 50 NSNumber for reference image position of portrait Array to landscape Array. The other two have 50 NSString elements with (1) name and (2) address of icon images. One Data class object is created in AppDelegate (load of application).

I start the catalog in Portrait, making the views by passing the portrait Array (with UIImages). When device turns left, I remake the views (releasing old views) passing the landscape Array. In xCode, all of it works fine!!! In device, when I turn device left (to remake the views), sometimes (I noticed when I have other apps opened) the app crash down with this message: "Program received signal: “0”. Data Formatters temporarily unavailable"

I know that this message refers to Memory Leaks problem, so my question is:

Using SQLite to store my data (actually in NSMutableArrays) I'll gain memory performance? I'm newbie in SQLite for iPhone. Is there any other开发者_开发技巧 solution to store my data?

Thank you all, guys!!!


This question is less about NSMutableArrays vs SQLite and more about memory usage. A UIImage will typically consume a lot of memory and should be released when not needed which is usually when it is not visible. Your application may have 0 leaks but will still crash. You will need to register for UIApplicationDidReceiveMemoryWarningNotification notifications and act accordingly. UIViewControllers already respond to - (void)didReceiveMemoryWarning which you can override. Now for storing these images on disk for when you need to release the memory you could use SQLite or what I would recommend, just create a cache folder.


I like SQLite as a solution. It is easy to provide a pre-populated DB, and beyond that you simply hook your app into some methods that can Add/Delete/Update records.

Your issue isn't going to be solved with SQLite - the problem is memory management. Get that wrong, and it doesn't matter where you store your data.

Separate the 2 concerns - displaying vs storage. Get the displaying to work right, then worry about where to store the data.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜