OOM Error occurred when the android studio profile was opened

做~自己de王妃 提交于 2019-12-24 10:23:52

问题


Android version : 8.0.0

When I call file.list, if I open the android studio profiler to monitor the memory, it is easy to OOM error, as follows:

java.lang.OutOfMemoryError: EnsureLocalCapacity
   at java.io.UnixFileSystem.list0(Native Method)
   at java.io.UnixFileSystem.list(UnixFileSystem.java:303)
   at java.io.File.list(File.java:1122)

I try to find problems from the source code ,List ends up calling list0 ,

file.list -> UnixFileSystem.list() -> UnixFileSystem_list0 :

Java_java_io_UnixFileSystem_list0(JNIEnv *env, jobject this,
                              jobject file)
{
DIR *dir = NULL;
struct dirent64 *ptr;
struct dirent64 *result;
int len, maxlen;
jobjectArray rv, old;
jclass str_class;

str_class = JNU_ClassString(env);
CHECK_NULL_RETURN(str_class, NULL);


WITH_FIELD_PLATFORM_STRING(env, file, ids.path, path) {
    dir = opendir(path);
} END_PLATFORM_STRING(env, path);
if (dir == NULL) return NULL;

ptr = malloc(sizeof(struct dirent64) + (PATH_MAX + 1));
if (ptr == NULL) {
    JNU_ThrowOutOfMemoryError(env, "heap allocation failed");
    closedir(dir);
    return NULL;
}
// ...
}

And, confusingly, the string that's returned here is "heap allocation failed" ,not “EnsureLocalCapacity” ,so I don't know where "EnsureLocalCapacity" from

here is my code :

private static final String LINUX_CURRENT_FD_NUM = "/proc/" + Process.myPid() + "/fd";
private final File mFdFile = new File(LINUX_CURRENT_FD_NUM);

private void getFdInfo(){
  final String[] fdFileList = mFdFile.list();
}


mContext.registerActivityLifecycleCallbacks(new 
Application.ActivityLifecycleCallbacks() {

        // ...

        @Override
        public void onActivityStopped(Activity activity) {
            getFdInfo();
        }

        // ...
    });

At present, it is found that it occurs under the premise of enabling profiler monitoring. It is not clear whether other conditions will occur.

A few questions:

  1. How to solve this problem?
  2. Is this problem related to profiler? Does turning on profiler memory monitoring consume memory? How much does it cost?
  3. where can see the profiler memory monitoring related source code

来源:https://stackoverflow.com/questions/55643820/oom-error-occurred-when-the-android-studio-profile-was-opened

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!