简体   繁体   English

iPhone App启动时会占用大量内存

[英]iPhone App has large memory footprint on startup

If I put a breakpoint on my first line of code from main function, I see in the activity monitor 17MB of memory for my app. 如果我在主函数的第一行代码上放置一个断点,则在活动监视器中我的应用程序会看到17MB的内存。 Do you have any idea why the memory usage is so high without anything loaded? 您是否知道为什么没有加载任何内容时内存使用率如此之高? (Maybe the OS is loading many things, but not me) (也许操作系统正在加载很多东西,但不是我)

This memory usage has almost the same size as the app executable. 此内存使用量与应用可执行文件的大小几乎相同。 Is the executable fully loaded at startup? 可执行文件在启动时是否已完全加载?
How can I reduce the initial memory size? 如何减小初始内存大小?

不要看活动监视器,而使用工具(配置文件,分配)。

I think the fact that it's the same size as your app bundle is probably just a coincidence because the whole bundle is not loaded into memory on startup. 我认为与应用程序捆绑包大小相同的事实可能只是一个巧合,因为整个捆绑包在启动时不会加载到内存中。

As CocoaFu said, use the allocations tool to see how much memory your app is allocating. 正如CocoaFu所说,请使用分配工具查看您的应用程序正在分配多少内存。 It will be much smaller than the activity monitor tool because it does not include memory used by OpenGL (which backs all user interface elements). 它将比活动监视器工具小得多,因为它不包括OpenGL使用的内存(支持所有用户界面元素)。

Most likely, you actual allocations are quite small (a MB or less) while the other 16 or so MB are all of the interface elements of your app being created by UIKit (ie your navigation controller, various view controllers, buttons, whatever). 您的实际分配很可能很小(一个MB或更少),而其他16个左右的MB是由UIKit创建的应用程序的所有界面元素(即,导航控制器,各种视图控制器,按钮等)。 Note that on an iPhone 4 or iPod touch 4th gen, the OpenGL allocations (ie the difference between the allocations tool and activity monitor tool) will be roughly two to four times the size than on earlier models because the screen has 4 times the resolution so all UI elements are larger. 请注意,在iPhone 4或iPod touch第4代上,OpenGL分配(即分配工具和活动监视器工具之间的差异)的大小约为早期型号的2-4倍,因为屏幕的分辨率为4倍,因此所有UI元素都更大。

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

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