首页 > 其他分享 >Android GC

Android GC

时间:2023-05-23 20:32:01浏览次数:47  
标签:VM objects GC 内存 heap Android Native


28470 dalvikvm D GC_FOR_MALLOC freed 665 objects / 239992 bytes in 71ms 28470 dalvikvm D GC_FOR_MALLOC freed 673 objects / 240288 bytes in 87ms 21940 dalvikvm D GC_EXPLICIT freed 4802 objects / 185320 bytes in 78ms 28470 dalvikvm D GC_FOR_MALLOC freed 666 objects / 240536 bytes in 63ms


 


GC_FOR_MALLOC means that the GC was triggered because there wasn't enough memory left on the heap to perform an allocation. Might be triggered when new objects are being created.

GC_EXPLICIT means that the garbage collector has been explicitly asked to collect, instead of being triggered by high water marks in the heap. Happens all over the place, but most likely when a thread is being killed or when a binder communication is taken down.

There are a few others as well:

GC_CONCURRENT Triggered when the heap has reached a certain amount of objects to collect.

GC_EXTERNAL_ALLOC means that the the VM is trying to reduce the amount of memory used for collectable objects, to make room for more non-collectable.

 

typedef enum {
    /* Not enough space for an "ordinary" Object to be allocated. */
    GC_FOR_MALLOC,
    /* Automatic GC triggered by exceeding a heap occupancy threshold. */
    GC_CONCURRENT,
    /* Explicit GC via Runtime.gc(), VMRuntime.gc(), or SIGUSR1. */
    GC_EXPLICIT,
    /* GC to try to reduce heap footprint to allow more non-GC'ed memory. */
    GC_EXTERNAL_ALLOC,
    /* GC to dump heap contents to a file, only used under WITH_HPROF */
    GC_HPROF_DUMP_HEAP
} GcReason;


Roughly speaking, the format is [Reason] [Amount Freed], [Heap Statistics], [External Memory Statistics], [Pause Time]

Reason

Robert/yuku already gave info on the meaning of these.

Amount Freed

E.g. freed 2125K

Self explanatory

Heap Statistics

E.g. 47% free 6214K/11719K

These numbers reflect conditions after the GC ran. The "47% free" and 6214K reflect the current heap usage. The 11719K represents the total heap size. From what I can tell, the heap can grow/shrink, so you will not necessarily have an OutOfMemoryError if you hit this limit.

External Memory Statistics

E.g external 7142K/8400K

Note: This might only exist in pre-Honeycomb versions of Android (pre 3.0).

Before Honeycomb, bitmaps are allocated external to your VM (e.g. Bitmap.createBitmap() allocates the bitmap externally and only allocates a few dozen bytes on your local heap). Other examples of external allocations are for java.nio.ByteBuffers.

Pause Time

If it's a concurrent GC event, there will be two times listed. One is for a pause before the GC, one is for a pause when the GC is mostly done. E.g. paused 3ms+5ms

For non-concurrent GC events, there is only one pause time and it's typically much bigger. E.g. paused 87ms

 

GC_EXTERNAL_ALLOC freed 297K, 49% free 3411K/6663K, external 24870K/26260K, paused 83ms

前面Free的内存是VM中java使用的内存,external是指VM中通过JNI中Native的类中的malloc分配出的内存,例如Bitmap和一些Cursor都是这么分配的。
在 Davilk中,给一个程序分配的内存根据机型厂商的不同,而不同,现在的大部分的是32M了,而在VM内部会把这些内存分成java使用的内存和 Native使用的内存,它们之间是不能共享的,就是说当你的Native内存用完了,现在Java又有空闲的内存,这时Native会重新像VM申请, 而不是直接使用java的。
例如上边的例子
free 3411K/6663K和external 24870K/26260K
如果这时需要创建一个2M的Bitmap,Native现有内存26260-24870=1390K<2048k,因此他就会向Vm申请内存,虽然java空闲的内存是
6663-3411=3252>2048,但这部分内存Native是不能使用。
但是你现在去申请2M的Native内存,VM会告诉你无法分配的,因为现在已使用的内存已经接近峰值了32M(26260+6663=32923 ),所以现在就会成force close 报OOM。
所以现在我们要检查我们的native内存的使用情况来避免OOM。

 

 

Reference :

http://stackoverflow.com/questions/4976566/what-do-gc-for-malloc-gc-explicit-and-other-gc-mean-in-android-logcat

标签:VM,objects,GC,内存,heap,Android,Native
From: https://blog.51cto.com/u_16125990/6334411

相关文章

  • gcd 证明
    gcd$gcd(a,b)$表示a与b的最大公约数。heregcd证明设有$gcd(a,b)=d(a>b)$,则$d|a$、$d|b$(也就是d既是a的因数也是b的因数)。设有$k=\lfloor\frac{a}{b}\rfloor$、$r=a\modb$,则$a=bk+r$。举个栗子,因为$a=5b+1=5\times2+1=11$,则\[\begin{c......
  • Android 触摸音的播放
    1.源码路径 frameworks\base\services\core\java\com\android\server\audio\AudioService.java.AudioService//==========================================================================================//SoundEffects//=====================......
  • 代码混淆及android配置
    1什么是代码混淆百度百科解释:代码混淆(Obfuscatedcode)亦称花指令,是将计算机程序的代码,转换成一种功能上等价,但是难于阅读和理解的形式的行为。代码混淆可以用于程序源代码,也可以用于程序编译而成的中间代码。执行代码混淆的程序被称作代码混淆器。已经存在许多种功能各异的代码......
  • APP测试 - 利用ABD命令将Android手机中已安装的APP导出为APK文件
    0.场景测试过程中部分迭代的APP与研发的版本不一致,又不知道具体是哪个版本。故需要导出测试出现问题的迭代APP用于复现问题 1.导出步骤1.1找到应用的包名方案A:查看手机安装的应用$adbshellpmlistpackage方案B:利用monitor监视要打开的APP$adbshellammonitor......
  • Android 单独Process 的 Service 触发 Application的构造
    今天在使用单独Process的Service(android:process,如果没有此attr就不会)时,发现该Serivce的启动会使得AndroidManifest中包裹此Service的Application再构造一个出来,想了想也合理,因为每个Application都对应一个Process,那么对于单独Process的service来说,是一个新进程,那么是需要构造出......
  • Android handler src track
    HandlerThread是真正干活的,本身就是一个Thread:HandlerThreadextendsThread主要比普通的Thread多了一个Looper,而hanlderThread的run函数其实很简单:@Overridepublicvoidrun(){mTid=Process.myTid();Looper.prepare();这一步就生了......
  • Android开发 UsageStatsManager应用使用情况管理
    前言  UsageStatsManager是用来知晓,设备中应用的使用情况的管理。它能给我们提供应用的进入前台动作与时间戳、进入后台的动作与时间戳、上次的使用时间、使用总时长等等信息。此功能在原生的设置-应用-使用统计中有所展示。所需权限<uses-permissionandroid:name="android.......
  • Android平台GB28181设备接入模块如何实现实时视频和本地录像双码流编码
    ​技术背景我们在做Android平台GB28181设备接入模块的时候,遇到这样的场景,比如执法记录仪或智慧工地等场景下,由于GB28181设备接入模块,注册到国标平台后,平时只是心跳保持,或还有实时位置订阅,查看视频的时候,是按需看,而且有时候,网络环境并不是太好,所以,催生了这样一个诉求:部分开发者希......
  • 修改Android 触摸提示音及音量大小
    一、修改代码提高系统的音量。代码路径:base/services/core/java/com/android/server/audio/AudioService.javaprivatestaticint[]MAX_STREAM_VOLUME=newint[]{5,//STREAM_VOICE_CALL7,//STREAM_SYSTEM7,//STREAM_RING15......
  • JVM中GC Roots及引用类型概述
    JVM中可以用作GCRoots的对象包括以下几种:活动线程(Activethreads):正在执行的线程被视为GCRoots,因为它们持有当前执行状态的信息。静态变量(Staticvariables):被声明为静态的变量属于类,因此它们会一直存在于内存中。JNI引用(JNIreferences):JavaNativeInterface(JNI)引用是在......