1

I have a screen that overlays the SpenSurfaceView with Android layout components. When the user switches the screen to load different components, the old components leak into this class:

com.samsung.android.sdk.pen.engine.SpenInView from the native stack according to MAT (Memory Analyzer T)

The overlayed components are custom controllers to take in user input in the form of strokes. They have a reference to the SurfaceView, but it is nulled before the components are deleted.

The problem remains even if I completely exit the application.

I am using example PenSample5_6_TextRecognition as reference.

This is using Samsung Mobile SDK (http://developer.samsung.com/samsung-mobile-sdk)

What strategy should I employ to continue to chase this memory leak ? The NDK side of the SDK is likely closed source.

Does the SpenObjectBase retains references to the SpenSurfaceView ?

Can somebody with more reputation than I have create the "spen sdk" tag.

tomrozb
  • 25,773
  • 31
  • 101
  • 122
jeremyvillalobos
  • 1,795
  • 2
  • 19
  • 39

1 Answers1

0

Please check onDestroy() from sample application. Do you close all resources?

@Override
protected void onDestroy() {
    super.onDestroy();

    if (mTextRecognition != null) {
        mSpenTextRecognitionManager.destroyRecognition(mTextRecognition);
        mSpenTextRecognitionManager.close();
    }

    if (mSpenSurfaceView != null) {
        mSpenSurfaceView.closeControl();
        mSpenSurfaceView.close();
        mSpenSurfaceView = null;
    }

    if(mSpenNoteDoc != null) {
        try {
            mSpenNoteDoc.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        mSpenNoteDoc = null;
    }
}

Samples are closing resources in onDestroy. That may happen well after user leaves activity (even never if device has enough memory). Consider releasing resources in onPause and re-creating them in onResume instead.

Finally, in my code I am removing registred callbacks private void removeListeners() { spenPageDocContainingNoteDoc.setObjectListener(null); try { spensBasicShapeConverter.setResultListener(null); } catch (Exception e) { .. }

When investingating heap dumps, I saw my Activity (callback handler) held inside some data structure in Spen API. Removing listeners removed that memory leak.

Bartosz Bilicki
  • 12,599
  • 13
  • 71
  • 113