简体   繁体   English

iPhone NSMutableArray与SQLite

[英]iPhone NSMutableArray vs. SQLite

I have an catalog developed for iPhone that is my first app. 我有一个为iPhone开发的目录,这是我的第一个应用程序。 Because of it, I have some problems with memory leaks and the app crash down when I have more than 55 photos in catalog. 因此,当目录中的照片超过55张时,我会遇到内存泄漏和应用程序崩溃的问题。 (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. 我的数据类有5个NSMutableArrays。 1 have 50 UIImage elements for Portrait. 1个有50个用于Portrait的UIImage元素。 The second have 25 UIImage elements for Landscap (catalog uses 2 portrait in 1 landscape image). 第二个有25个用于Landscap的UIImage元素(目录使用2个肖像合1个风景图像)。 Other have 50 NSNumber for reference image position of portrait Array to landscape Array. 其他有50个NSNumber作为纵向Array到横向Array的参考图像位置。 The other two have 50 NSString elements with (1) name and (2) address of icon images. 另外两个具有50个NSString元素,分别具有图标图像的(1)名称和(2)地址。 One Data class object is created in AppDelegate (load of application). 在AppDelegate(应用程序负载)中创建一个Data类对象。

I start the catalog in Portrait, making the views by passing the portrait Array (with UIImages). 我以Portrait启动目录,通过传递portrait Array(带有UIImages)来创建视图。 When device turns left, I remake the views (releasing old views) passing the landscape Array. 当设备向左转时,我将重新制作通过横向Array的视图(释放旧视图)。 In xCode, all of it works fine!!! 在xCode中,所有这些都可以正常工作!!! 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" 在设备中,当我向左转设备(以重新制作视图)时,有时(当我打开其他应用程序时注意到),该应用程序崩溃并显示以下消息:“程序收到信号:“ 0”。数据格式化程序暂时不可用”

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? 使用SQLite存储我的数据(实际上在NSMutableArrays中)我将获得内存性能吗? I'm newbie in SQLite for iPhone. 我是iPhone的SQLite的新手。 Is there any other solution to store my data? 还有其他解决方案来存储我的数据吗?

Thank you all, guys!!! 谢谢大家!

This question is less about NSMutableArray s vs SQLite and more about memory usage. 这个问题与NSMutableArraySQLite而与内存使用有关。 A UIImage will typically consume a lot of memory and should be released when not needed which is usually when it is not visible. UIImage通常会占用大量内存,并且在不需要时应释放​​它,通常在不可见时才释放。 Your application may have 0 leaks but will still crash. 您的应用程序可能有0个泄漏,但仍然会崩溃。 You will need to register for UIApplicationDidReceiveMemoryWarningNotification notifications and act accordingly. 您将需要注册UIApplicationDidReceiveMemoryWarningNotification通知并采取相应措施。 UIViewController s already respond to - (void)didReceiveMemoryWarning which you can override. UIViewController已经响应- (void)didReceiveMemoryWarning ,您可以对其进行覆盖。 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. 现在,当您需要释放内存时,可以将这些图像存储在磁盘上了,可以使用SQLite或我建议的方式,只需创建一个缓存文件夹即可。

I like SQLite as a solution. 我喜欢SQLite作为解决方案。 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. SQLite不会解决您的问题-问题是内存管理。 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. 使显示正常工作,然后担心在哪里存储数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM