Jason Hartley
Jason Hartley

Reputation: 2499

Programmatically get weak global reference table count

Is there a way in Java or Kotlin to programmatically get a count of global weak references being used by native code in a closed-source 3rd party library?

I'm using the Esri ArcGIS runtime SDK in an Android app and I've noticed that calls to a certain static computational method (GeometryEngine.union()) involves native code that is creating global weak references that aren't being released. After the app runs for several hours, it eventually crashes with something like this displayed in logcat:

A  Abort message: 'JNI ERROR (app bug): weak global reference table overflow (max=51200)weak global reference table dump:
    Last 10 entries (of 51200):
      51199: 0x13c7b8c0 com.esri.arcgisruntime.internal.jni.CoreTask
      51198: 0x13c76670 com.esri.arcgisruntime.internal.jni.CoreTask
      51197: 0x13c71420 com.esri.arcgisruntime.internal.jni.CoreTask
      51196: 0x13c695d0 com.esri.arcgisruntime.internal.jni.CoreTask
      51195: 0x13c5f680 com.esri.arcgisruntime.internal.jni.CoreTask
      51194: 0x13c59eb0 com.esri.arcgisruntime.internal.jni.CoreTask
      51193: 0x13c51560 com.esri.arcgisruntime.internal.jni.CoreTask
      51192: 0x13c4c310 com.esri.arcgisruntime.internal.jni.CoreTask
      51191: 0x13c444c0 com.esri.arcgisruntime.internal.jni.CoreTask
      51190: 0x13bb9fd0 com.esri.arcgisruntime.internal.jni.CoreTask
    Summary:
      51050 of com.esri.arcgisruntime.internal.jni.CoreTask (51050 unique instances)
         57 of com.esri.arcgisruntime.internal.jni.j (19 unique instances)
         28 of com.esri.arcgisruntime.internal.jni.CoreVector (28 unique instances)
         22 of java.lang.DexCache (22 unique instances)
         10 of com.esri.arcgisruntime.internal.jni.CoreMapView (1 unique instances)
          8 of dalvik.system.PathClassLoader (5 unique instances)
          4 of com.esri.arcgisruntime.internal.jni.CoreArcGISTiledLayer (1 unique instances)
          4 of com.esri.arcgisruntime.internal.jni.CoreMap (1 unique instances)
          3 of com.esri.arcgisruntime.internal.jni.CoreBasemap (1 unique instances)

Perhaps there is something I've implemented incorrectly that isn't allowing these references to be cleaned up, or perhaps the memory leak is Esri's fault. Either way, I'd like to be able to see the count of global weak references so I can detect when this leak is ocurring (and perhaps display it in the UI) without having to run a memory profiler or other debugging tool, and without having to wait 8 hours for the app to crash.

Upvotes: 1

Views: 161

Answers (0)

Related Questions