5

In my android application I make extensive use of a native method that returns some data.

However after a number of calls I obtain a crash.

The native called method is :

static jbyteArray JNIGetIcon(JNIEnv* e, jclass clazz)
{
    ByteBuffer buff;
    buff.Write(*icon, 48, 32, r66Api::IBitmap::TEncoding::EEnc_Rgba8888);

    jbyteArray result = GetEnv()->NewByteArray(buff.Size());
    GetEnv()->SetByteArrayRegion(result, 0, buff.Size(), (jbyte*)  buff.GetData());

    return result;     
}

Could someone point me to what I'm doing wrong ?

the crash log is:

02-10 18:33:32.075 W/dalvikvm(10644*10644): ReferenceTable overflow (max=1024)
02-10 18:33:32.075 W/dalvikvm(10644*10644): Last 10 entries in JNI pinned array reference table:
02-10 18:33:32.075 W/dalvikvm(10644*10644): 1014: 0x2fc77de0 cls=[C (28 bytes)
02-10 18:33:32.075 W/dalvikvm(10644*10644): 1015: 0x2fc79b88 cls=[C (28 bytes)
02-10 18:33:32.075 W/dalvikvm(10644*10644): 1016: 0x2fc79c38 cls=[C (28 bytes)
02-10 18:33:32.085 W/dalvikvm(10644*10644): 1017: 0x2fc79ef8 cls=[C (28 bytes)
02-10 18:33:32.085 W/dalvikvm(10644*10644): 1018: 0x2fc79fa8 cls=[C (28 bytes)
02-10 18:33:32.085 W/dalvikvm(10644*10644): 1019: 0x2fc7a050 cls=[C (28 bytes)
02-10 18:33:32.085 W/dalvikvm(10644*10644): 1020: 0x2fc7a0f0 cls=[C (28 bytes)
02-10 18:33:32.105 W/dalvikvm(10644*10644): 1021: 0x2fc7a190 cls=[C (28 bytes)
02-10 18:33:32.105 W/dalvikvm(10644*10644): 1022: 0x2fc7a240 cls=[C (28 bytes)
02-10 18:33:32.105 W/dalvikvm(10644*10644): 1023: 0x2fc7a2e8 cls=[C (28 bytes)
02-10 18:33:32.115 W/dalvikvm(10644*10644): JNI pinned array reference table summary (1024 entries):
02-10 18:33:32.115 W/dalvikvm(10644*10644): 6 of [C 20B (5 unique)
02-10 18:33:32.115 W/dalvikvm(10644*10644): 1013 of [C 28B (237 unique)
02-10 18:33:32.125 W/dalvikvm(10644*10644): 2 of [C 36B (2 unique)
02-10 18:33:32.125 W/dalvikvm(10644*10644): 1 of [C 52B
02-10 18:33:32.125 W/dalvikvm(10644*10644): 1 of [C 68B
02-10 18:33:32.125 W/dalvikvm(10644*10644): 1 of [C 92B
02-10 18:33:32.125 W/dalvikvm(10644*10644): Memory held directly by native code is 7020 bytes
02-10 18:33:32.135 E/dalvikvm(10644*10644): Failed adding to JNI pinned array ref table (1024 entries)
02-10 18:33:32.135 I/dalvikvm(10644*10644): "main" prio=5 tid=3 RUNNABLE
02-10 18:33:32.135 I/dalvikvm(10644*10644): | group="main" sCount=0 dsCount=0 s=N obj=0x2aaca308 self=0xbe08
02-10 18:33:32.135 I/dalvikvm(10644*10644): | sysTid=10644 nice=0 sched=0/0 cgrp=unknown handle=1877224116
02-10 18:33:32.135 I/dalvikvm(10644*10644): at android.graphics.Canvas.drawText(Native Method)
02-10 18:33:32.145 I/dalvikvm(10644*10644): at android.text.BoringLayout.draw(BoringLayout.java:363)
02-10 18:33:32.145 I/dalvikvm(10644*10644): at android.widget.TextView.onDraw(TextView.java:4052)
02-10 18:33:32.155 I/dalvikvm(10644*10644): at android.view.View.draw(View.java:6535)
02-10 18:33:32.155 I/dalvikvm(10644*10644): at android.view.ViewGroup.drawChild(ViewGroup.java:1531)
02-10 18:33:32.155 I/dalvikvm(10644*10644): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1258)
02-10 18:33:32.165 I/dalvikvm(10644*10644): at android.view.View.draw(View.java:6538)
02-10 18:33:32.165 I/dalvikvm(10644*10644): at android.view.View.buildDrawingCache(View.java:6297)
02-10 18:33:32.165 I/dalvikvm(10644*10644): at android.view.View.getDrawingCache(View.java:6086)
02-10 18:33:32.165 I/dalvikvm(10644*10644): at android.view.ViewGroup.drawChild(ViewGroup.java:1456)
02-10 18:33:32.175 I/dalvikvm(10644*10644): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1258)
Florian Margaine
  • 58,730
  • 15
  • 91
  • 116
rantravee
  • 7,411
  • 9
  • 35
  • 47

1 Answers1

7

I think you're looking at the wrong function. According to the log message you've got a whole bunch of pinned character arrays (the "[C"). 1013 of them to be exact.

Look for a GetStringChars or GetStringCritical call that doesn't have a matching Release.

fadden
  • 51,356
  • 5
  • 116
  • 166
  • 1
    Thanks ! . After a lot of search work I found that indeed somewhere I did a "GetStringChars()" and I called "ReleaseStringChars" only if it was a copy (isCopy == JNI_TRUE) . I'm really curios how did you figure it out, just by looking at the log. Anyway thanks again ! – rantravee Feb 11 '11 at 10:11
  • 2
    If you Get, you must Release, regardless of what isCopy holds (if it's not a copy, then the original must be pinned down to prevent the GC from moving it, so you have to Release it to un-pin the data). How I figured it out: the log says "JNI pinned array reference table", which only applies to the String and GetArrayElements calls. For "[C" (array of char) the GetStringChars function is the most likely culprit. – fadden Feb 12 '11 at 00:36
  • Hello, I have a very similar problem. I have compiled a database library with the NDK which had already all the JNI functions. Now I'm using one some of theses functions and after a while of loading data into the database I get this " ReferenceTable overflow (max=1024)" error. How can I find out where the problem occurs and where can I get more information about this. – white_gecko Oct 12 '11 at 19:32