Skip to content

java.lang.OutOfMemoryError: pthread_create (1040KB stack) failed: Try again

xiaoniudonghe2015 edited this page Sep 19, 2018 · 3 revisions

1. 错误log:

java.lang.OutOfMemoryError: pthread_create (1040KB stack) failed: Try again
    	at java.lang.Thread.nativeCreate(Native Method)
    	at java.lang.Thread.start(Thread.java:1063)
    	at com.link.callfree.d.c.b.b(PushUtil.java:273)
    	at com.link.callfree.modules.profile.c.i(FragmentProfile.java:257)
    	at com.link.callfree.modules.profile.c.c(FragmentProfile.java:60)
    	at com.link.callfree.modules.profile.c$3.onReceive(FragmentProfile.java:600)
    	at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:988)
    	at android.os.Handler.handleCallback(Handler.java:739)
    	at android.os.Handler.dispatchMessage(Handler.java:95)
    	at android.os.Looper.loop(Looper.java:145)
    	at android.app.ActivityThread.main(ActivityThread.java:6946)
    	at java.lang.reflect.Method.invoke(Native Method)
    	at java.lang.reflect.Method.invoke(Method.java:372)
    	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404)
    	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)

2. 错位定位在:

new Thread(new Runnable() {
                @Override
                public void run() {
                    try {
                        LoadAppIconThread.getImageURI(context, pushAppInfo, file, action);
                    } catch (Exception e) {
                        if (DEBUG) Log.i(TAG, e.toString());
                    }
                }
}).start();

3. 错误分析:错误发生在推荐位下载图片创建线程时

/proc/sys/kernel/threads-max,规定了每个进程创建线程数目的上限. 对于32位的系统,当进程的逻辑地址空间不够的时候也会产生OOM,每个线程通常需要mapp 1MB左右的stack空间(stack大小可以自行设置),32为系统进程逻辑地址4GB,用户空间少于3GB。逻辑地址空间不够(已用逻辑空间地址可以查看/proc/pid/status中的VmPeak/VmSize记录).线程数受限导致创建线程时clone failed导致了OOM

4. 解决

使用Glide的方式加载推荐位图片

Clone this wiki locally