1

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.

5
  • This answer tells me how to do it in Xamarin, but how to do it in Java/Kotlin? stackoverflow.com/a/43414425/1301891 Commented Apr 5, 2023 at 19:11
  • Have you reported this issue to the SDK vendor? The count of weak globals is not exposed and would require burrowing deep into the Android runtime internals to get at. Commented Apr 6, 2023 at 8:03
  • I found Debug.dumpReferenceTables(), but it's a hidden method. Commented Apr 6, 2023 at 16:51
  • Yes, the only alternative I see is to go hacking at the ART internals, which is feasible for an internal application but not so much for one you put on the Play store. Commented Apr 6, 2023 at 19:34
  • @Botje, this app will never be in the app store, so if you have any advice on how to do this, I welcome it. Commented Apr 7, 2023 at 2:15

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.