开发者

iPhone: How much memory usage is too much? [closed]

开发者 https://www.devze.com 2023-01-11 22:55 出处:网络
开发者_开发问答 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references,or expertise, but this question will likely so
开发者_开发问答 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 11 years ago.

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


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.


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.

0

精彩评论

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