fixed #727: invoke DeleteLocalRef() to resolve memory leak

This commit is contained in:
minggo 2011-09-20 14:25:16 +08:00
parent 5ff9bd0c9e
commit 762e342b4d
6 changed files with 38 additions and 16 deletions

View File

@ -45,6 +45,7 @@ extern "C"
if (env != 0 && classOfCocos2dxActivity != 0)
{
ret = env->GetStaticMethodID(classOfCocos2dxActivity, methodName, paramCode);
env->DeleteLocalRef(classOfCocos2dxActivity);
}
if (! ret)
@ -62,8 +63,9 @@ extern "C"
if (preloadBackgroundMusicMethodID)
{
jstring StringArg = env->NewStringUTF(path);
env->CallStaticVoidMethod(classOfCocos2dxActivity, preloadBackgroundMusicMethodID, StringArg);
jstring stringArg = env->NewStringUTF(path);
env->CallStaticVoidMethod(classOfCocos2dxActivity, preloadBackgroundMusicMethodID, stringArg);
env->DeleteLocalRef(stringArg);
}
}
@ -74,9 +76,9 @@ extern "C"
if (playBackgroundMusicMethodID)
{
jstring StringArg = env->NewStringUTF(path);
env->CallStaticVoidMethod(classOfCocos2dxActivity, playBackgroundMusicMethodID, StringArg, isLoop);
//env->ReleaseStringUTFChars(StringArg, path);
jstring stringArg = env->NewStringUTF(path);
env->CallStaticVoidMethod(classOfCocos2dxActivity, playBackgroundMusicMethodID, stringArg, isLoop);
env->DeleteLocalRef(stringArg);
}
}
@ -172,8 +174,9 @@ extern "C"
if (playEffectMethodID)
{
jstring StringArg = env->NewStringUTF(path);
ret = env->CallStaticIntMethod(classOfCocos2dxActivity, playEffectMethodID, StringArg, bLoop);
jstring stringArg = env->NewStringUTF(path);
ret = env->CallStaticIntMethod(classOfCocos2dxActivity, playEffectMethodID, stringArg, bLoop);
env->DeleteLocalRef(stringArg);
}
return (unsigned int)ret;
@ -233,8 +236,9 @@ extern "C"
if (preloadEffectMethodID)
{
jstring StringArg = env->NewStringUTF(path);
env->CallStaticVoidMethod(classOfCocos2dxActivity, preloadEffectMethodID, StringArg);
jstring stringArg = env->NewStringUTF(path);
env->CallStaticVoidMethod(classOfCocos2dxActivity, preloadEffectMethodID, stringArg);
env->DeleteLocalRef(stringArg);
}
}
@ -245,8 +249,9 @@ extern "C"
if (unloadEffectMethodID)
{
jstring StringArg = env->NewStringUTF(path);
env->CallStaticVoidMethod(classOfCocos2dxActivity, unloadEffectMethodID, StringArg);
jstring stringArg = env->NewStringUTF(path);
env->CallStaticVoidMethod(classOfCocos2dxActivity, unloadEffectMethodID, stringArg);
env->DeleteLocalRef(stringArg);
}
}
}

View File

@ -69,9 +69,16 @@ public:
* and data.
* use this appoach to decrease the jni call number
*/
jstring jstrText = methodInfo.env->NewStringUTF(text);
jstring jstrFont = methodInfo.env->NewStringUTF(pFontName);
methodInfo.env->CallStaticVoidMethod(methodInfo.classID, methodInfo.methodID, methodInfo.env->NewStringUTF(text),
methodInfo.env->NewStringUTF(pFontName), (int)fontSize, eAlignMask, nWidth, nHeight);
methodInfo.env->DeleteLocalRef(jstrText);
methodInfo.env->DeleteLocalRef(jstrFont);
methodInfo.env->DeleteLocalRef(methodInfo.classID);
return true;
}

View File

@ -54,6 +54,7 @@ extern "C"
"()V"))
{
t.env->CallStaticVoidMethod(t.classID, t.methodID);
t.env->DeleteLocalRef(t.classID);
}
}

View File

@ -80,19 +80,23 @@ extern "C"
, "showMessageBox"
, "(Ljava/lang/String;Ljava/lang/String;)V"))
{
jstring StringArg1;
jstring stringArg1;
if (! pszTitle)
{
StringArg1 = t.env->NewStringUTF("");
stringArg1 = t.env->NewStringUTF("");
}
else
{
StringArg1 = t.env->NewStringUTF(pszTitle);
stringArg1 = t.env->NewStringUTF(pszTitle);
}
jstring StringArg2 = t.env->NewStringUTF(pszMsg);
t.env->CallStaticVoidMethod(t.classID, t.methodID, StringArg1, StringArg2);
jstring stringArg2 = t.env->NewStringUTF(pszMsg);
t.env->CallStaticVoidMethod(t.classID, t.methodID, stringArg1, stringArg2);
t.env->DeleteLocalRef(stringArg1);
t.env->DeleteLocalRef(stringArg2);
t.env->DeleteLocalRef(t.classID);
}
}
@ -110,6 +114,7 @@ extern "C"
, "()V"))
{
t.env->CallStaticObjectMethod(t.classID, t.methodID);
t.env->DeleteLocalRef(t.classID);
}
}

View File

@ -68,6 +68,7 @@ extern "C"
"()V"))
{
t.env->CallStaticVoidMethod(t.classID, t.methodID);
t.env->DeleteLocalRef(t.classID);
}
}
@ -81,6 +82,7 @@ extern "C"
"()V"))
{
t.env->CallStaticVoidMethod(t.classID, t.methodID);
t.env->DeleteLocalRef(t.classID);
}
}
}

View File

@ -50,6 +50,7 @@ extern "C"
"()Ljava/lang/String;"))
{
jstring str = (jstring)t.env->CallStaticObjectMethod(t.classID, t.methodID);
t.env->DeleteLocalRef(t.classID);
CCString *ret = new CCString(JniHelper::jstring2string(str).c_str());
ret->autorelease();
@ -74,6 +75,7 @@ extern "C"
, "()Ljava/lang/String;"))
{
jstring str = (jstring)t.env->CallStaticObjectMethod(t.classID, t.methodID);
t.env->DeleteLocalRef(t.classID);
CCString *ret = new CCString(JniHelper::jstring2string(str).c_str());
ret->autorelease();