ndk 内存溢出
- 原因: jbyte jbarray = (jbyte )malloc(len * sizeof(jbyte)); 没有及时释放内存
- log日志现象: SystemDeviceService ,还有一些系统级的服务全部重启,同时也尝试重启我的程序,但是又重新Force close 了.
01-01 08:30:56.673 483-1055/system_process W/ActivityManagerService: Scheduling restart of crashed service com.android.smspush/.WapPushManager in 121880ms
01-01 08:30:56.677 483-500/system_process W/ActivityManagerService: Scheduling restart of crashed service com.google.android.googlequicksearchbox/com.google.android.voiceinteraction.GsaVoiceInteractionService in 131875ms
01-01 08:30:57.264 483-545/system_process W/InputDispatcher: channel '2bb22717 com.analysis.SmartCameraClear/com.analysis.zheshan.analysis.MainActivity (server)' ~ Consumer closed input channel or an error occurred. events=0x9
01-01 08:30:57.264 483-545/system_process E/InputDispatcher: channel '2bb22717 com.analysis.SmartCameraClear/com.analysis.zheshan.analysis.MainActivity (server)' ~ Channel is unrecoverably broken and will be disposed!
01-01 08:30:57.268 483-1055/system_process W/InputDispatcher: Attempted to unregister already unregistered input channel '2bb22717 com.analysis.SmartCameraClear/com.analysis.zheshan.analysis.MainActivity (server)'
01-01 08:30:57.322 483-855/system_process W/ActivityManagerService: Scheduling restart of crashed service com.analysis.SmartCameraClear/com.analysis.zheshan.analysis.MyService in 141230ms
01-01 08:30:57.323 483-855/system_process W/ActivityManagerService: Force removing ActivityRecord{224c3dc3 u0 com.analysis.SmartCameraClear/com.analysis.zheshan.analysis.MainActivity t38}: app died, no saved state
01-01 08:30:57.929 19493-19493/com.android.launcher3 W/Launcher: setApplicationContext called twice! old=com.android.launcher3.LauncherApplication@92b3b26 new=com.android.launcher3.LauncherApplication@92b3b26
结论:
- Android studio 使用Monitor 无法看到jni内部的内存状况.
- jni 内存被加载到系统内存中,导致系统内存不足,,系统级服务没有内存空间可以使用.把Android 系统整崩了, 因而系统程序重新运行.
jni 内存调用的确不能小瞧啊,系统都能整重启了.来两篇博客长记性吧
[JNI官方规范中文版 ]
[JNI中的内存管理]