首页 文章 精选 留言 我的

精选列表

搜索[内存溢出],共10000篇文章
优秀的个人博客,低调大师

android-手机内存分配和回收机制研究

Theory: There are two kinds ofmemory allocationmechanism : (1)Somelargeapplication ,like oracle client ,world of warcraft game : ( We can think about it likeBuffet(自助餐),if you paid, you can control what you eat and do not need to pay anymore ) This kind of application will have aminimum configurationof memory ( for example ,the WOW game will have at least 1gigabyte memory) ,this minimum memory is the largest estimation of the memory that it may use,it will never ask the Operation System for extra memory when runningit .(For example ,the wow.exe only need 400m memory ,the left memory are reserved for temp files ,swap files ,object files and so on ,so even it only needs 400M,the rest 600M are unavailable for other application .) So this kind of application has only two status: (Can run / cannot run),Once it runs ,it will always run and do not need to worry about the memory . (2)Small application: Most of the normal application are acted like this way ,it applies for a small memory ,and when it runs and needs more memory ,it asked the Operation system for more memory. (we can think it as “Choose dishes from menu”(点菜),if we needs more ,we order more ,pay more) So this kind of application will have three status: (cannot run /Can run/ can run but future the memory used out) During running ,it needs more memory and applied from OS ,so maybe onetime ,the OS cannot supply enough memory, this application will shutdown. Our issue: Based on the above theory ,we can take a look at the problem ,why sometimes ,the application will shut down if we scroll the screen very frequently in search result page. Because android mobile application is usingMechanism 2 Problem:when we go to the search result page ,if we scroll down the screen very frequently ,the application thread will shut down because of the memory used out. Phenomenon: scroll down very frequently ->Dalvik VM used out exception Reason: The Heap memory can be divided into parts,one is reserved for java objects ,the other is reserved for native C objects.(They cannot mix together) If we scroll up /down the screen very frequently ,the new native objects are created andONLY the native heap memory are recycled. And the recycling speed is much slower than the allocating memory speed ,that’s why the heap memory will used out. From the log ,we can see ,that only native heap memory are recycled (GC_EXTERNAL_ALLOC stands for the native heap memory recycle) And most the memory recycled are small( less than 150KB) ,that’s because android based on “slab” mechanism to allocate memory ,and the slab has a limit size. But what the size of the native heap memory it allocated when a new native c object created? The answer is320KBin our test So,allocate more and recycle less ,at last ,the memory will used out and the application process will die. Solution; When configure the emulator ,pleaseset the RAM(SD card) to be a large number ,and restart the emulator. Go to <ANDROID_ROOT>\.android\avd\<Your avd>\config.ini ,change thesdcard.size 本文转自 charles_wang888 51CTO博客,原文链接:http://blog.51cto.com/supercharles888/835923,如需转载请自行联系原作者

资源下载

更多资源
Mario

Mario

马里奥是站在游戏界顶峰的超人气多面角色。马里奥靠吃蘑菇成长,特征是大鼻子、头戴帽子、身穿背带裤,还留着胡子。与他的双胞胎兄弟路易基一起,长年担任任天堂的招牌角色。

Nacos

Nacos

Nacos /nɑ:kəʊs/ 是 Dynamic Naming and Configuration Service 的首字母简称,一个易于构建 AI Agent 应用的动态服务发现、配置管理和AI智能体管理平台。Nacos 致力于帮助您发现、配置和管理微服务及AI智能体应用。Nacos 提供了一组简单易用的特性集,帮助您快速实现动态服务发现、服务配置、服务元数据、流量管理。Nacos 帮助您更敏捷和容易地构建、交付和管理微服务平台。

Sublime Text

Sublime Text

Sublime Text具有漂亮的用户界面和强大的功能,例如代码缩略图,Python的插件,代码段等。还可自定义键绑定,菜单和工具栏。Sublime Text 的主要功能包括:拼写检查,书签,完整的 Python API , Goto 功能,即时项目切换,多选择,多窗口等等。Sublime Text 是一个跨平台的编辑器,同时支持Windows、Linux、Mac OS X等操作系统。

WebStorm

WebStorm

WebStorm 是jetbrains公司旗下一款JavaScript 开发工具。目前已经被广大中国JS开发者誉为“Web前端开发神器”、“最强大的HTML5编辑器”、“最智能的JavaScript IDE”等。与IntelliJ IDEA同源,继承了IntelliJ IDEA强大的JS部分的功能。

用户登录
用户注册