iPhone NSMutableArray 与 SQLite

发布于 2024-11-01 20:39:35 字数 724 浏览 6 评论 0原文

我有一个为 iPhone 开发的目录,这是我的第一个应用程序。因此,当目录中的照片超过 55 张时,我会遇到内存泄漏和应用程序崩溃的问题。 (我会解释它何时崩溃)

我已经使用泄漏性能工具进行了测试,并且成功修复了泄漏,但我的应用程序仍然崩溃。

我的 Data 类有 5 个 NSMutableArray。 1 有 50 个用于肖像的 UIImage 元素。第二个有 25 个用于 Landscap 的 UIImage 元素(目录在 1 个横向图像中使用 2 个纵向图像)。其他还有 50 个 NSNumber,用于纵向 Array 到横向 Array 的参考图像位置。另外两个有 50 个 NSString 元素,其中包含 (1) 名称和 (2) 图标图像的地址。在AppDelegate(应用程序加载)中创建一个Data 类对象。

我在 Portrait 中启动目录,通过传递纵向数组(使用 UIImages)来制作视图。当设备向左转时,我重新制作传递景观数组的视图(释放旧视图)。在xCode中,一切都正常!在设备中,当我向左转动设备(以重新制作视图)时,有时(我注意到当我打开其他应用程序时)应用程序崩溃并显示以下消息: “程序接收到的信号:“0”。 数据格式化程序暂时不可用”

我知道这条消息指的是内存泄漏问题,所以我的问题是:

使用 SQLite 存储我的数据(实际上在 NSMutableArrays 中)我会获得内存性能吗?我是 iPhone 版 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!!!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

安人多梦 2024-11-08 20:39:35

这个问题与 NSMutableArraySQLite 的关系不大,更多的是关于内存使用情况。 UIImage 通常会消耗大量内存,应该在不需要时释放,通常是在它不可见时。你的应用程序可能有 0 泄漏,但仍然会崩溃。您需要注册 UIApplicationDidReceiveMemoryWarningNotification 通知并采取相应措施。 UIViewController 已经响应您可以覆盖的 - (void)didReceiveMemoryWarning 。现在,为了将这些图像存储在磁盘上,以便在需要释放内存时,可以使用 SQLite 或我推荐的方法,只需创建一个缓存文件夹即可。

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.

岁吢 2024-11-08 20:39:35

我喜欢 SQLite 作为解决方案。提供预填充的数据库很容易,除此之外,您只需将应用程序连接到一些可以添加/删除/更新记录的方法即可。

SQLite 无法解决您的问题 - 问题在于内存管理。如果搞错了,数据存储在哪里并不重要。

将两个问题分开——显示与存储。让显示正常工作,然后担心在哪里存储数据。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文