Is there a way to do it? I am aware garbage collector in java will eventually do it if I dereference it. However I need to immediately clear the byte array memory as it is critical memory(passwords etc). Thus I was trying to clear memory via JNI. Is there a way to do it?
My java code :
public void clearBytes(byte[] data) {
clear(data);
}
//private native method clear(byte[] bytes);
private native void clear(byte[] arr);
And Here's my JNI code
JNIEXPORT void JNICALL Java_com_java_self_EncryptorUtil_clear(JNIEnv *env, jobject obj, jbyteArray arr)
{
//code to free/delete/clear memory
free(arr);
return;
}
I am trying to clear the same memory as pointed to by "data" Please tell me if you guys need anything else.
Thanks.