jniReferenceTableoverflow-创新互联
频繁点击一个按钮,程序崩溃,查看log部分详情如下:
十余年的莲池网站建设经验,针对设计、前端、开发、售后、文案、推广等六对一服务,响应快,48小时及时工作处理。营销型网站的优势是能够根据用户设备显示端的尺寸不同,自动调整莲池建站的显示方式,使网站能够适用不同显示终端,在浏览器中调整网站的宽度,无论在任何一种浏览器上浏览网站,都能展现优雅布局与设计,从而大程度地提升浏览体验。创新互联从事“莲池网站设计”,“莲池网站推广”以来,每个客户项目都认真落实执行。04-11 11:10:40.371: W/dalvikvm(5507): ReferenceTable overflow (max=1024) 04-11 11:10:40.371: W/dalvikvm(5507): JNI pinned array reference table (0x6242b008) dump: 04-11 11:10:40.371: W/dalvikvm(5507): Last 10 entries (of 1024): 04-11 11:10:40.371: W/dalvikvm(5507): 1023: 0x42e97298 int[] (456 elements) 04-11 11:10:40.371: W/dalvikvm(5507): 1022: 0x41c16618 int[] (69 elements) 04-11 11:10:40.371: W/dalvikvm(5507): 1021: 0x42e5ef28 byte[] (1280 elements) 04-11 11:10:40.371: W/dalvikvm(5507): 1020: 0x4230da28 byte[] (119 elements) 04-11 11:10:40.371: W/dalvikvm(5507): 1019: 0x422a03f0 byte[] (14 elements) 04-11 11:10:40.371: W/dalvikvm(5507): 1018: 0x42efced0 byte[] (1920 elements) 04-11 11:10:40.371: W/dalvikvm(5507): 1017: 0x422bc570 byte[] (119 elements) 04-11 11:10:40.371: W/dalvikvm(5507): 1016: 0x41f52e68 byte[] (14 elements) 04-11 11:10:40.371: W/dalvikvm(5507): 1015: 0x423c41d0 byte[] (119 elements) 04-11 11:10:40.371: W/dalvikvm(5507): 1014: 0x422b8bf0 byte[] (14 elements) 04-11 11:10:40.371: W/dalvikvm(5507): Summary: 04-11 11:10:40.371: W/dalvikvm(5507): 20 of byte[] (12 elements) (20 unique instances) 04-11 11:10:40.371: W/dalvikvm(5507): 1 of byte[] (13 elements) 04-11 11:10:40.371: W/dalvikvm(5507): 489 of byte[] (14 elements) (489 unique instances) 04-11 11:10:40.371: W/dalvikvm(5507): 1 of byte[] (68 elements) 04-11 11:10:40.371: W/dalvikvm(5507): 3 of byte[] (69 elements) (3 unique instances) 04-11 11:10:40.371: W/dalvikvm(5507): 486 of byte[] (119 elements) (486 unique instances) 04-11 11:10:40.371: W/dalvikvm(5507): 10 of byte[] (148 elements) (10 unique instances) 04-11 11:10:40.371: W/dalvikvm(5507): 10 of byte[] (152 elements) (10 unique instances) 04-11 11:10:40.371: W/dalvikvm(5507): 1 of byte[] (1280 elements) 04-11 11:10:40.371: W/dalvikvm(5507): 1 of byte[] (1920 elements) 04-11 11:10:40.371: W/dalvikvm(5507): 1 of int[] (69 elements) 04-11 11:10:40.371: W/dalvikvm(5507): 1 of int[] (456 elements) 04-11 11:10:40.371: E/dalvikvm(5507): Failed adding to JNI pinned array ref table (1024 entries) 04-11 11:10:40.371: I/dalvikvm(5507): "main" prio=5 tid=1 RUNNABLE
主要问题是ReferenceTable overflow 。查看资料,发现是引用计数器溢出了,大为1024.即java的内存管理机制是基于引用的,需要计数器来记录引用的次数。在overflow这句话下面dump出了最近的10个引用,Summary下面可以看出有哪些引用。可以发现其中有两组byte[],每组的引用达到480多次。我恍然大悟,每点击一次按钮,引用一次,下次点击时上次的资源未被释放。于是一直累加直至计数器溢出。
检查代码发现:
int nArrLen_u = env->GetArrayLength(jbUrl); if(nArrLen_u > 0){ pUrl = (char *)malloc(nArrLen_u + 1); bzero(pUrl, (nArrLen_u + 1)); jU = env->GetByteArrayElements(jbUrl, NULL); memcpy(pUrl, jU, nArrLen_u); } int nArrLen_x = env->GetArrayLength(jbXml); if(nArrLen_x > 0){ pXmlBuf = (char *)malloc(nArrLen_x + 1); bzero(pXmlBuf, (nArrLen_x + 1)); jX = env->GetByteArrayElements(jbXml, NULL); memcpy(pXmlBuf, jX, nArrLen_x); }
代码上可以看出我调用了两次 GetByteArrayElements 但是却没有释放掉。所以在最后添上释放语句就解决了~
if(nArrLen_u > 0){ env->ReleaseByteArrayElements(jbUrl,jU,0); } if(nArrLen_x > 0){ env->ReleaseByteArrayElements(jbXml,jX,0); }
参考Android NDK之JNI陷阱 在用到NewByteArray类似方法时一定要DeleteLocalRef(),使用GetByteArrayElements时 要用ReleaseByteArrayElements来进行释放。
问题就是答案!真正明白是什么问题之后,也就找到了答案。
另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。
分享题目:jniReferenceTableoverflow-创新互联
网页URL:http://azwzsj.com/article/dspdgi.html