Skip to content
This repository was archived by the owner on Apr 4, 2023. It is now read-only.

Commit 184c17a

Browse files
ML Kit camera causes a memory leak #738
1 parent 298fcc1 commit 184c17a

1 file changed

Lines changed: 11 additions & 8 deletions

File tree

src/mlkit/mlkit-cameraview.android.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class SizePair {
1919

2020
// TODO pause/resume handling
2121
export abstract class MLKitCameraView extends MLKitCameraViewBase {
22-
private surfaceView: android.view.SurfaceView;
22+
private surfaceView: any; // android.view.SurfaceView;
2323
private bytesToByteBuffer = new Map();
2424
private pendingFrameData = null;
2525
protected rotation;
@@ -29,24 +29,27 @@ export abstract class MLKitCameraView extends MLKitCameraViewBase {
2929

3030
disposeNativeView(): void {
3131
super.disposeNativeView();
32-
if (this.detector) {
33-
this.detector.close();
34-
this.detector = undefined;
35-
}
36-
this.bytesToByteBuffer = new Map();
3732
this.surfaceView = null;
38-
33+
3934
if (this.camera != null) {
4035
this.camera.stopPreview();
4136
this.camera.setPreviewCallbackWithBuffer(null);
4237
try {
4338
this.camera.setPreviewDisplay(null);
4439
} catch (e) {
45-
console.log(e);
40+
console.log("Error cleaning up the ML Kit camera (you can probably ignore this): " + e);
4641
}
4742
this.camera.release();
4843
this.camera = null;
4944
}
45+
this.bytesToByteBuffer.clear();
46+
47+
if (this.detector) {
48+
this.detector.close();
49+
this.detector = undefined;
50+
}
51+
this.lastVisionImage = null;
52+
this.pendingFrameData = null;
5053
}
5154

5255
createNativeView(): Object {

0 commit comments

Comments
 (0)