문제

I have this code which is called from onPreviewFrame() (actually, a wrapper function calls this code, but does nothing except call it), which is supposed to do some OpenCV operations on a preview frame. The problem is that It keeps throwing an OOM error after a few cycles, so i stripped the code to its minimal that still throws this error.

int ContrastMeasure(JNIEnv* env, jobject obj, jbyteArray yuv, jint pw, jint ph)
{
    if (isContrastBusy)
    {
        return 0;
    }
    isContrastBusy = true;
    jbyte* _yuv = env->GetByteArrayElements(yuv, 0);
    delete [] _yuv;
    isContrastBusy = false;
    return 0;
}

Its been ages since I used c++, so I know my mistake could be really stupid. I tried env->DeleteLocalRef(obj);, and also 'delete _yuv;' but to no avail.

what is taking all this memory, and how do I free it?

도움이 되었습니까?

해결책

You need to ReleaseByteArrayElements as well: (and not delete)

http://docs.oracle.com/javase/1.5.0/docs/guide/jni/spec/functions.html

GetArrayElements Routines

NativeType *GetArrayElements(JNIEnv *env, ArrayType array, jboolean *isCopy);

A family of functions that returns the body of the primitive array. The result is valid until the corresponding ReleaseArrayElements() function is called. Since the returned array may be a copy of the Java array, changes made to the returned array will not necessarily be reflected in the original array until ReleaseArrayElements() is called.

See the bold part.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top