頻繁點(diǎn)擊一個(gè)按鈕,程序崩潰,查看log部分詳情如下:
十余年的蓮池網(wǎng)站建設(shè)經(jīng)驗(yàn),針對(duì)設(shè)計(jì)、前端、開發(fā)、售后、文案、推廣等六對(duì)一服務(wù),響應(yīng)快,48小時(shí)及時(shí)工作處理。營銷型網(wǎng)站的優(yōu)勢(shì)是能夠根據(jù)用戶設(shè)備顯示端的尺寸不同,自動(dòng)調(diào)整蓮池建站的顯示方式,使網(wǎng)站能夠適用不同顯示終端,在瀏覽器中調(diào)整網(wǎng)站的寬度,無論在任何一種瀏覽器上瀏覽網(wǎng)站,都能展現(xiàn)優(yōu)雅布局與設(shè)計(jì),從而大程度地提升瀏覽體驗(yàn)。創(chuàng)新互聯(lián)從事“蓮池網(wǎng)站設(shè)計(jì)”,“蓮池網(wǎng)站推廣”以來,每個(gè)客戶項(xiàng)目都認(rèn)真落實(shí)執(zhí)行。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 。查看資料,發(fā)現(xiàn)是引用計(jì)數(shù)器溢出了,大為1024.即java的內(nèi)存管理機(jī)制是基于引用的,需要計(jì)數(shù)器來記錄引用的次數(shù)。在overflow這句話下面dump出了最近的10個(gè)引用,Summary下面可以看出有哪些引用??梢园l(fā)現(xiàn)其中有兩組byte[],每組的引用達(dá)到480多次。我恍然大悟,每點(diǎn)擊一次按鈕,引用一次,下次點(diǎn)擊時(shí)上次的資源未被釋放。于是一直累加直至計(jì)數(shù)器溢出。
檢查代碼發(fā)現(xiàn):
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); }
代碼上可以看出我調(diào)用了兩次 GetByteArrayElements 但是卻沒有釋放掉。所以在最后添上釋放語句就解決了~
if(nArrLen_u > 0){ env->ReleaseByteArrayElements(jbUrl,jU,0); } if(nArrLen_x > 0){ env->ReleaseByteArrayElements(jbXml,jX,0); }
參考Android NDK之JNI陷阱 在用到NewByteArray類似方法時(shí)一定要DeleteLocalRef(),使用GetByteArrayElements時(shí) 要用ReleaseByteArrayElements來進(jìn)行釋放。
問題就是答案!真正明白是什么問題之后,也就找到了答案。
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場(chǎng)景需求。