更新时间:2022-12-27 11:45:14
我终于解决了这个问题。我花了几个小时思考为什么我的应用程序可能会占用更多的RAM比愤怒的小鸟或涂鸦跳。这只是没有意义,因为我的应用程序没有CALayer绘图,或复杂的Open GL图形渲染,或沉重的网络连接。
我发现这幻灯片,而搜索答案和幻灯片17列出了减少内存占用的方法。突然出现的一件事是PNGCrush(图形压缩)。
我的应用程序包含很多自定义图形(PNG文件),但我没有想到它们影响我的app
在安装 PNGCrush 之后,系统会显示图片(未正确优化)强大>并使用它在一个特别大的图像(3.2 MB),然后删除几个未使用的图像我最终减少我的应用程序内存占用从60+ MB和严重滞后到35 MB和没有滞后。这花了五分钟的时间。
我没有完成粉碎我的所有图片,但是当我做到的时候,我会更新每个人的最终内存。 / p>
对于所有感兴趣的人,这里是一个链接到解释如何安装PNGCrush 的博客(非常复杂)。
UPDATE:我现在使用一个名为 ImageOptim ,可为多个脚本(如PNGCrush)提供GUI。简短描述:
ImageOptim无缝集成各种优化工具:PNGOUT,AdvPNG, PNGCrush ,扩展OptiPNG,
这是一个链接到网站免费下载OS X 10.6 - 10.8。请注意,我不是此软件的开发人员,发布商或广告客户。
I recently launched an app on the AppStore. After testing on the simulator thousands of times, and actual devices hundreds of times we finally released our app.
Reviews started popping up about app crashes when the user launches the app. We figured that the app crashes on launch on iOS devices with less than (or equal to) 256 Mb of RAM. The following devices are devices our app supports with less than 256:
The app doesn't always crash. Sometimes it launches fine and runs smoothly. Other times it crashes. The time from launch (when the user taps the icon) to crash is usually two seconds, which would mean that the system isn't shutting it down.
When using Instruments to test on certain devices, I find the following:
Because of what I see as "over-allocation", the result is:
This app takes (on average) 60 MB of Real Memory and 166 MB of Virtual. When the app launches the memory being used quickly increases until it reaches about 60 MB at which point the view has been loaded. Here is a snapshot of the Activity Monitor in Instruments:
I know that those figures are WAYY to high (although the CPU % never really gets up there). I am worried that ARC is not working properly, or the more likely case: I'm not allocating objects correctly. What could possibly be happening?
In Xcode, there are only a few warnings, none of which pertain to the app launch or any files associated with the launching of the app. I placed breakpoints in both the App Delegate and my viewDidLoad
method to check and see if the crash occurred there - it didn't.
Also, Xcode never generates any errors or messages in the debugger. There are also no crash reports in iTunes Connect, it just says, "Too few reports have been submitted for a report to be shown." I've added crash reporting to my app, but I haven't released that version.
I started using Obj-C just as ARC arrived, so I'm new to dealing with memory, allocation, etc. (that is probably obvious) but I'd like to know a few things:
How can I use @autoreleasepool
to reduce my memory impact? What do I do with memory warnings, what do I write in the didRecieveMemoryWarning
since I'm using ARC?
Would removing NSLog statements help speed things up?
And the most important question:
Why does my app take up so much memory and how can I reduce my whopping 60 MB footprint?
I'd really appreciate any help! Thanks in advance!
EDIT: After testing on the iPhone 4 (A4), we noticed that the app doesn't crash when run whereas on devices with less than 256 MB of RAM it does.
I finally solved the issue. I spent a few hours pondering why my application could possibly take up more RAM than Angry Birds or Doodle Jump. That just didn't make sense, because my app does no CALayer Drawing, or complex Open GL Graphics Rendering, or heavy web connection.
I found this slideshow while searching for answers and slide 17 listed the ways to reduce memory footprint. One thing that stuck out was PNGCrush (Graphics Compression).
My app contains a lot of custom graphics (PNG files), but I hadn't thought of them affecting my app in any way, apparently images (when not optimized properly) severely increase an applications memory footprint.
After installing PNGCrush and using it on a particularly large image (3.2 MB) and then deleting a few unused images I ended up reducing my apps memory footprint from 60+ MB and severe lag to 35 MB and no lag. That took a whopping five minutes.
I haven't finished "crushing" all my images, but when I do I'll update everyone on the final memory footprint.
For all those interested, here is a link to a blog that explains how to install PNGCrush (it's rather complicated).
UPDATE: Instead of using the PNGCrush process (which is very helpful, although time consuming with lots of images) I now use a program called ImageOptim that provides a GUI for multiple scripts like PNGCrush. Heres a short description:
ImageOptim seamlessly integrates various optimisation tools: PNGOUT, AdvPNG, PNGCrush, extended OptiPNG, JpegOptim, jpegrescan, jpegtran, and Gifsicle.
Here's a link to the website with a free download for OS X 10.6 - 10.8. Note, I am not a developer, publisher or advertiser of this software.