Returning a newly create object from a C Native function
Hi all,
I have a native C function thatsupposedly returns a new Object:
...
cls = (*env)->FindClass(env,"LMyClass;");
mid = (*env)->GetMethodID(env, cls,"<init>","II(V)");
return (*env)->NewObject(env, cls, mid, i, j);
}
My question is: Is this snip code correct? I mean, I've tried this and when I return from the function, a NullPointerException is thrown from the line that called the native function.
Is the reference returned by NewObject a Local Reference and as such when the funtion returns the object is garbage collected? If so a solution would be to return a GlobalReference of this new object:
...
return (*env)->NewGlobalReference(env, (*env)->NewObject(env, cls, mid, i, j) );
}
But I would like to escape this solution as I would have the task to delete all objects created in such a manner thus making little or no use at all of the JAVA's garbage collector facility.
Any ideas or sugestions are most welcome,
Ric

