GREF increasing / decreasing in multi-threaded service (aidl) - what does it mean? GREF increasing / decreasing in multi-threaded service (aidl) - what does it mean? multithreading multithreading

GREF increasing / decreasing in multi-threaded service (aidl) - what does it mean?


These are JNI global references. If you're not writing native code, you don't have direct control over them. The log messages appear when CheckJNI is enabled, which is on by default for engineering builds and the emulator.

The messages just mean that native code is telling the VM that it's not allowed to discard some objects. In essence, global refs are a way for native code to add references to the GC's root set. Assuming the native code is written correctly, the global refs will be cleared when the native code no longer has need of them.

The only cause for concern would be if the global ref count continued to climb, as that would suggest a global reference leak. Since the VM can't free the objects, a global ref leak will eventually cause the VM to run out of memory. To help identify such problems, a cap is placed on the number of global references when CheckJNI is enabled (current limit is 2000).