cocos2dx3.10 android 出现local reference table overflow (max=512) 崩溃,呈上日志

03-13 16:16:15.772: E/dalvikvm(7900): JNI ERROR (app bug): local reference table overflow (max=512)
03-13 16:16:15.772: W/dalvikvm(7900): JNI local reference table (0x4c410c08) dump:
03-13 16:16:15.772: W/dalvikvm(7900): Last 10 entries (of 512):
03-13 16:16:15.772: W/dalvikvm(7900): 511: 0x2cd70f78 byte[] (4 elements)
03-13 16:16:15.772: W/dalvikvm(7900): 510: 0x2cd70f58 java.net.InetAddress[] (2 elements)
03-13 16:16:15.772: W/dalvikvm(7900): 509: 0x2cd70f30 libcore.io.StructAddrinfo
03-13 16:16:15.772: W/dalvikvm(7900): 508: 0x2cd70ef0 java.lang.String “114.215.40.240”
03-13 16:16:15.772: W/dalvikvm(7900): 507: 0x2c7e1080 libcore.io.Posix
03-13 16:16:15.772: W/dalvikvm(7900): 506: 0x2cd70648 com.android.okhttp.internal.http.HttpURLConnectionImpl
03-13 16:16:15.772: W/dalvikvm(7900): 505: 0x2cddf988 com.android.okhttp.internal.http.HttpURLConnectionImpl
03-13 16:16:15.772: W/dalvikvm(7900): 504: 0x2cdcc9d0 com.android.okhttp.internal.http.HttpURLConnectionImpl
03-13 16:16:15.772: W/dalvikvm(7900): 503: 0x2cdcf0e0 com.android.okhttp.internal.http.HttpURLConnectionImpl
03-13 16:16:15.772: W/dalvikvm(7900): 502: 0x2cdaec88 com.android.okhttp.internal.http.HttpURLConnectionImpl
03-13 16:16:15.773: W/dalvikvm(7900): Summary:
03-13 16:16:15.773: W/dalvikvm(7900): 1 of java.lang.Class
03-13 16:16:15.773: W/dalvikvm(7900): 1 of java.lang.String
03-13 16:16:15.773: W/dalvikvm(7900): 1 of byte[] (4 elements)
03-13 16:16:15.774: W/dalvikvm(7900): 1 of libcore.io.StructAddrinfo
03-13 16:16:15.774: W/dalvikvm(7900): 1 of libcore.io.Posix
03-13 16:16:15.774: W/dalvikvm(7900): 505 of com.android.okhttp.internal.http.HttpURLConnectionImpl (505 unique instances)
03-13 16:16:15.774: W/dalvikvm(7900): 1 of java.net.InetAddress[] (2 elements)
03-13 16:16:15.774: E/dalvikvm(7900): Failed adding to JNI local ref table (has 512 entries)
03-13 16:16:15.774: I/dalvikvm(7900): “Thread-188” prio=5 tid=17 RUNNABLE
03-13 16:16:15.775: I/dalvikvm(7900): | group=“main” sCount=0 dsCount=0 obj=0x2caff940 self=0x4e669bd8
03-13 16:16:15.775: I/dalvikvm(7900): | sysTid=7928 nice=0 sched=0/0 cgrp=[fopen-error:2] handle=1310697288
03-13 16:16:15.775: I/dalvikvm(7900): | state=R schedstat=( 0 0 0 ) utm=582 stm=98 core=1
03-13 16:16:15.775: I/dalvikvm(7900): at libcore.io.Posix.getaddrinfo(Native Method)
03-13 16:16:15.775: I/dalvikvm(7900): at libcore.io.ForwardingOs.getaddrinfo(ForwardingOs.java:61)
03-13 16:16:15.776: I/dalvikvm(7900): at java.net.InetAddress.parseNumericAddressNoThrow(InetAddress.java:269)
03-13 16:16:15.776: I/dalvikvm(7900): at java.net.InetAddress.parseNumericAddress(InetAddress.java:483)
03-13 16:16:15.776: I/dalvikvm(7900): at java.net.URI.isValidHost(URI.java:556)
03-13 16:16:15.776: I/dalvikvm(7900): at java.net.URI.parseAuthority(URI.java:491)
03-13 16:16:15.776: I/dalvikvm(7900): at java.net.URI.parseURI(URI.java:409)
03-13 16:16:15.776: I/dalvikvm(7900): at java.net.URI.(URI.java:204)
03-13 16:16:15.777: I/dalvikvm(7900): at java.net.URL.toURILenient(URL.java:518)
03-13 16:16:15.777: I/dalvikvm(7900): at com.android.okhttp.internal.Platform.toUriLenient(Platform.java:63)
03-13 16:16:15.777: I/dalvikvm(7900): at com.android.okhttp.internal.http.HttpEngine.(HttpEngine.java:162)
03-13 16:16:15.777: I/dalvikvm(7900): at com.android.okhttp.internal.http.HttpURLConnectionImpl.newHttpEngine(HttpURLConnectionImpl.java:275)
03-13 16:16:15.777: I/dalvikvm(7900): at com.android.okhttp.internal.http.HttpURLConnectionImpl.initHttpEngine(HttpURLConnectionImpl.java:261)
03-13 16:16:15.777: I/dalvikvm(7900): at com.android.okhttp.internal.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:86)
03-13 16:16:15.777: I/dalvikvm(7900): at org.cocos2dx.lib.Cocos2dxHttpURLConnection.connect(Cocos2dxHttpURLConnection.java:154)
03-13 16:16:15.777: I/dalvikvm(7900): at dalvik.system.NativeStart.run(Native Method)
03-13 16:16:15.778: E/dalvikvm(7900): VM aborting
03-13 16:16:15.778: A/libc(7900): Fatal signal 6 (SIGABRT) at 0x00001edc (code=-6), thread 7928 (Thread-182)

感觉是httpclient引起的啊?

如何重现?

就是我一直频繁的通过http请求图片,然后用精灵加载,次数多了就这样了。我看网上说local reference table overflow (max=512) 都是调用jni 没释放对象造成的,但是我并没有调用,只是请求图片,不知道是什么原因造成这个的,困扰2天了。(对了,标题写错了不是3.10,是3.4)

我记得以前用quick-3.3的时候,如果在安卓上同时堆积的请求过多的话,会直接崩溃。

大神,这个有没有什么好的解决方法呢?我也并不是同时请求,只是请求的次数多了就会崩,我看日志一直在输出
03-14 11:16:23.371: D/dalvikvm(4336): GC_FOR_ALLOC freed 388K, 21% free 2931K/3708K, paused 13ms, total 13ms
03-14 11:16:23.424: D/dalvikvm(4336): GC_FOR_ALLOC freed 57K, 20% free 2989K/3708K, paused 14ms, total 14ms
03-14 11:16:23.501: D/dalvikvm(4336): GC_FOR_ALLOC freed 115K, 17% free 3105K/3708K, paused 13ms, total 13ms
03-14 11:16:23.502: I/dalvikvm-heap(4336): Grow heap (frag case) to 3.646MB for 472482-byte allocation
03-14 11:16:23.517: D/dalvikvm(4336): GC_FOR_ALLOC freed 230K, 21% free 3336K/4172K, paused 14ms, total 14ms

那应该是网络请求的jni调用写法有问题,没有及时释放引用。我看一下。

我测试了tests/extensions/HttpClientTest,连续200次网络请求没问题。

我测试的都是基本上就是在请求505次后就崩掉的。
现在找到一个方法就是请求到一定次数之后手动调用了HttpClient::getInstance()->destroyInstance() 释放。

Ok,那我多几次网络请求看一下。