I'm not sure what I'm doing wrong. Basically I'm making a bunch of calls to NewByteArray(), putting the result in a call to NewGlobalRef(), and then later calling DeleteGlobalRef(). That's exactly what I should be doing, right? Because for some reason I am still getting out of memory errors. I've been looking at the logs of my app as it runs, and I see things like this:
GC_FOR_ALLOC freed <1K, 2% free 14659K/14836K, paused 32ms, total 32ms
But that doesn't make sense to me. Why was it only about to free <1K when a moment earlier I had just called DeleteGlobalRef() on a byte array that was hundreds of KB? It's like the calls to DeleteGlobalRef() have no effect.
If anyone wants to look at some code, it's here. AndroidFileStream is the relevant class.
Any ideas?
--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-ndk...@googlegroups.com.
To post to this group, send email to andro...@googlegroups.com.
Visit this group at http://groups.google.com/group/android-ndk?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
When you say, "custom scoped JNI reference types with pass / release semantics," are you talking about something like std::unique_ptr<>, except that automatically calls Delete___Ref() when it goes out of scope?
So I still need to call DeleteLocalRef() on the inputStream reference, even though I'm creating a global reference from it and deleting that later on?
When you say, "custom scoped JNI reference types with pass / release semantics," are you talking about something like std::unique_ptr<>, except that automatically calls Delete___Ref() when it goes out of scope?
you usually don't have to delete local refs, unless.... you make so many of them, that it triggers one of dalvik's exceptions. An example of this would be doing something like NewStringUTF in a loop. Allocating too much "java" memory, or creating too many locals (512 in dalvik, and something like 16 in java) will be a problem.
Then this isn't true?
"A local reference is valid only within the dynamic context of the native method that creates it, and only within that one invocation of the native method. All local references created during the execution of a native method will be freed once the native method returns."
source: http://192.9.162.55/docs/books/jni/html/refs.html#27431