Permalink
Browse files

more memory fixes

  • Loading branch information...
1 parent be00676 commit 07fd0db72f16eafb32748c9cc546e255542c6dfe @joeferner committed Jul 25, 2012
Showing with 16 additions and 17 deletions.
  1. +10 −3 src/javaObject.cpp
  2. +4 −12 src/utils.cpp
  3. +2 −2 src/utils.h
View
@@ -26,7 +26,8 @@
JNIEnv *env = self->m_java->getJavaEnv();
- std::list<jobject> methods = javaReflectionGetMethods(env, self->m_class);
+ std::list<jobject> methods;
+ javaReflectionGetMethods(env, self->m_class, &methods);
jclass methodClazz = env->FindClass("java/lang/reflect/Method");
jmethodID method_getName = env->GetMethodID(methodClazz, "getName", "()Ljava/lang/String;");
for(std::list<jobject>::iterator it = methods.begin(); it != methods.end(); it++) {
@@ -45,7 +46,8 @@
env->DeleteLocalRef(*it);
}
- std::list<jobject> fields = javaReflectionGetFields(env, self->m_class);
+ std::list<jobject> fields;
+ javaReflectionGetFields(env, self->m_class, &fields);
jclass fieldClazz = env->FindClass("java/lang/reflect/Field");
jmethodID field_getName = env->GetMethodID(fieldClazz, "getName", "()Ljava/lang/String;");
for(std::list<jobject>::iterator it = fields.begin(); it != fields.end(); it++) {
@@ -172,7 +174,12 @@ JavaObject::~JavaObject() {
return ThrowException(javaExceptionToV8(env, errStr.str()));
}
- return scope.Close(javaToV8(self->m_java, env, val));
+ v8::Handle<v8::Value> result = javaToV8(self->m_java, env, val);
+
+ env->DeleteLocalRef(field);
+ env->DeleteLocalRef(val);
+
+ return scope.Close(result);
}
/*static*/ void JavaObject::fieldSetter(v8::Local<v8::String> property, v8::Local<v8::Value> value, const v8::AccessorInfo& info) {
View
@@ -8,9 +8,7 @@
#define MODIFIER_STATIC 9
-std::list<jobject> javaReflectionGetMethods(JNIEnv *env, jclass clazz) {
- std::list<jobject> results;
-
+void javaReflectionGetMethods(JNIEnv *env, jclass clazz, std::list<jobject>* methods) {
jclass clazzclazz = env->GetObjectClass(clazz);
jmethodID clazz_getMethods = env->GetMethodID(clazzclazz, "getMethods", "()[Ljava/lang/reflect/Method;");
jclass methodClazz = env->FindClass("java/lang/reflect/Method");
@@ -24,16 +22,12 @@ std::list<jobject> javaReflectionGetMethods(JNIEnv *env, jclass clazz) {
if((methodModifiers & MODIFIER_STATIC) == MODIFIER_STATIC) {
continue;
}
- results.push_back(method);
+ methods->push_back(method);
}
env->DeleteLocalRef(methodObjects);
-
- return results;
}
-std::list<jobject> javaReflectionGetFields(JNIEnv *env, jclass clazz) {
- std::list<jobject> results;
-
+void javaReflectionGetFields(JNIEnv *env, jclass clazz, std::list<jobject>* fields) {
jclass clazzclazz = env->GetObjectClass(clazz);
jmethodID clazz_getFields = env->GetMethodID(clazzclazz, "getFields", "()[Ljava/lang/reflect/Field;");
jclass fieldClazz = env->FindClass("java/lang/reflect/Field");
@@ -47,11 +41,9 @@ std::list<jobject> javaReflectionGetFields(JNIEnv *env, jclass clazz) {
if((fieldModifiers & MODIFIER_STATIC) == MODIFIER_STATIC) {
continue;
}
- results.push_back(field);
+ fields->push_back(field);
}
env->DeleteLocalRef(fieldObjects);
-
- return results;
}
std::string javaToString(JNIEnv *env, jstring str) {
View
@@ -42,8 +42,8 @@ struct DynamicProxyData {
int dynamicProxyDataVerify(DynamicProxyData* data);
-std::list<jobject> javaReflectionGetMethods(JNIEnv *env, jclass clazz);
-std::list<jobject> javaReflectionGetFields(JNIEnv *env, jclass clazz);
+void javaReflectionGetMethods(JNIEnv *env, jclass clazz, std::list<jobject>* methods);
+void javaReflectionGetFields(JNIEnv *env, jclass clazz, std::list<jobject>* fields);
std::string javaToString(JNIEnv *env, jstring str);
std::string javaObjectToString(JNIEnv *env, jobject obj);
JNIEnv* javaAttachCurrentThread(JavaVM* jvm);

0 comments on commit 07fd0db

Please sign in to comment.