Release java references in the JNI for calls going from native to Java
AVRCP Target's native avrcp_service heavily relies on JNI calls to get the current state of media on the device from the Java based Media Framework. When we make calls from native and receive references to Java objects we need to be certain we free those references so that the Java GC can clean up the memory. We fail to do so in many places, which has led to memory leaks. The biggest issue is with Bitmap image references that leak and cause a build up of memory relatively quickly since they're quite large. This change aims to add DeleteLocalRef() calls to all the Java objects we create in the JNI. Note that JNI types that represent language primatives (jint, jbyte, jboolean, etc.) are mapped to native c++ types and don't need to be freed. But, jobjects, jstr, and arrays all need to be freed. Tag: #stability Bug: 192800249 Test: atest BluetoothInstrumentationTests Test: Tested with a car that continually makes GetItemAttribute requests, allowing the memory leak to build up quickly. Showed that the crashes coming from the leak no longer happen. Change-Id: I70333640e9e941422223252d2858f96d3a96c8f9 Merged-In: I70333640e9e941422223252d2858f96d3a96c8f9
Loading
Please register or sign in to comment