iPhone:多少内存使用量算太多?

发布于 2024-09-15 03:31:37 字数 450 浏览 5 评论 0原文

我想这是一个非常奇怪的问题,但我以前从未真正处理过内存分配,所以现在我真的对使用太多内存或忘记释放东西感到偏执。我发现了非常有用的内存泄漏工具(并且很自豪地看到,至少到目前为止,我没有以这种方式丢失任何东西),还有分配工具,我认为它是用于测量使用了多少内存在应用程序运行时的任何给定点。但是,我不太确定我应该用掉多少内存。

我认为我的 iPod touch 中有 256M 内存,不太确定,但我不知道系统进程占用了多少内存,也不知道在遇到内存不足问题之前我可以安全使用多少内存。目前,我的程序占用了大约 4 MB 的空间,对于它正在执行的操作来说,这似乎相当高,但我猜其中至少有一些是无法停止的系统进程,或者是高维护性的东西,比如我正在做的大型图形背景。使用。

简而言之,有人可以给我一个很好的基准数据,我的应用程序应该以任何给定时间使用的最大内存量为目标吗? iPhone 4 和 iPad 的数据也不错,如果它们差异很大的话。

-灰

This is a pretty weird question I guess, but I've never really had to deal with memory allocation before so now I'm really paranoid about using too much of it or forgetting to deallocate stuff. I've found the extremely useful memory leak tool (and am quite proud to see that, so far at least, I'm not losing anything that way) and also the Allocations tool which I assume is for measuring how much memory is used up at any given point of application runtime. However, I'm not really certain how much memory I should be using up.

I think there's a good 256M in my iPod touch, not too sure, but I don't know how much of that is taken up by system processes, nor really how much I can safely use before I start running into low memory issues. At the moment my program's taking up around 4 MB, which seems pretty high for what it's doing but I guess at least some of that is system processes that can't be stopped, or high-maintenance stuff like the large graphical backdrop I'm using.

In short, can someone give me a good benchmark figure that my applications should aim for in terms of the maximum amount of memory used at any given time? Figures for iPhone 4 and iPad would be nice too, if these differ significantly.

-Ash

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

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

发布评论

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

评论(2

岁吢 2024-09-22 03:31:37

没有什么难的答案。有几点需要注意:

1) 如果您的应用程序随着时间的推移使用越来越多的内存,那么它会比大多数时候正确释放内存但会犯一些错误的应用程序更快被杀死。不要忘记有一个看门狗进程,它有一个(看似)复杂的杀死应用程序的公式,并且不同的应用程序可以出于不同的原因在不同的内存使用级别被杀死。

2) iPhone4 的内存比以前的手机大很多,但用户要同时处理多项任务,只用内存进城是很不礼貌的。对于这里的多任务处理来说,保持较低的内存占用比任何任务都更重要(当您自己的应用程序在后台时它会有所帮助,使用的内存越多,它被杀死的可能性就越大)。

3)认真对待内存警告并转储所有可以转储的内容。它将使您的应用程序运行更长时间,并再次帮助它在后台运行更长时间。

There's no hard answer. There are a few things to note:

1) If your app uses more and more memory over time, it will be killed a lot sooner than an app that releases memory properly most of the time, but makes a few mistakes. Don't forget there is a watchdog process that has a (seemingly) complex formula for killing applications, and that different apps can be killed at different levels of memory use for different reasons.

2) The iPhone4 has a lot more memory than the previous phones BUT with users multitasking, it's really rude to just go to town with memory use. With multitasking here it's more important than every to keep your memory footprint low (and it helps when your own app is in the background, the more memory is uses the more likely it is to be killed).

3) Treat memory warnings seriously and dump EVERYTHING you can. It will keep your app running longer and again help it live on in the background for a longer time.

阳光下的泡沫是彩色的 2024-09-22 03:31:37

在过去的两天里,我正在分析最新应用程序的内存占用情况,我发现了一个有趣的事实:

当应用程序收到内存警告时,它会释放当前不可见的视图。这导致我的应用程序崩溃,因为我没有考虑到这一点。我最初认为这是释放已自动释放的对象,但这是不正确的。

如果我重新启动手机,它可以在堆中处理最多 8mb 的数据,而不会发出任何警告。我想在 iOS4 中这也取决于你在后台运行了多少东西。我的 iPhone4 上有 iOS 4.0.1。

iPad/iPhone 3GS有256mb,iPhone4有512mb,但这并不意味着它全部可供一个进程使用。我记得在 iOS 3.0 早期,我的一个应用程序在 32mb 时被操作系统终止。

For the last 2 days I am analyzing the memory footprint of my latest app and I discovered an interesting fact:

When the application receives a memory warning, it deallocates views that are not currently visible. This causes my application to crash, as I didn't take that into account. I originally thought it was deallocating objects that had been autoreleased, but this is not correct.

If I'd reboot my phone it can handle up to 8mb in the heap without any warnings. I guess in iOS4 it depends how much stuff you run in the background as well. I have iOS 4.0.1 on iPhone4.

iPad/iPhone 3GS have 256mb, iPhone4 has 512mb, however it does not mean its all available to a process. I remember in early iOS 3.0 one of my apps was terminated by OS at 32mb.

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