How to remove jstring sent from Native Code back to Java?

I have the following native routine:

void sendMessage(const char* text)
{
    JNIEnv* env;

    if(!_jvm)
        return;

    _jvm->AttachCurrentThread(&env, NULL);

    if(!_nativesCls)
        _nativesCls = env->FindClass("com/foo/BaseLib");
    if(_nativesCls == 0)
            return;

    jstring message = env->NewStringUTF(text);
    if(!_sendStr)
        _sendStr = env->GetStaticMethodID(_nativesCls, "onMessage", "(Ljava/lang/String;)V");
    if(_sendStr)
        env->CallStaticVoidMethod(_nativesCls, _sendStr, message);
    //env->ReleaseStringUTFChars(message, text); // <----- * NOT WORKING
}

If I run it as it is, it works fine until the memory is full, and I get:

ReferenceTable overflow (max = 512)

I thought adding the comment line above would fix the problem, but it just makes the application bomb at that moment.

Any suggestions?

+3
source share
1 answer

Source: https://habr.com/ru/post/1784315/


All Articles