From 9ba1adba42d372bcc68fa8dd5f1a76a46269fab0 Mon Sep 17 00:00:00 2001 From: David Werth Date: Thu, 25 Apr 2024 07:40:24 +0200 Subject: [PATCH] #557 ZxingScannerComponent is not releasing all resources - BrowserCodeReader still trying to decode after ngDestroy --- .../zxing-scanner/src/lib/zxing-scanner.component.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/projects/zxing-scanner/src/lib/zxing-scanner.component.ts b/projects/zxing-scanner/src/lib/zxing-scanner.component.ts index df92737..b1b43d5 100644 --- a/projects/zxing-scanner/src/lib/zxing-scanner.component.ts +++ b/projects/zxing-scanner/src/lib/zxing-scanner.component.ts @@ -837,6 +837,18 @@ export class ZXingScannerComponent implements OnInit, OnDestroy { return; } + this.scanStop(); + try { + const videoElement = this.previewElemRef.nativeElement; + BrowserCodeReader.cleanVideoSource(videoElement); + } catch (err) { + } + + try { + BrowserCodeReader.releaseAllStreams(); + } catch (err) { + } + // clearing codeReader first to prevent setOptions error appearing in several Chromium versions this._codeReader = undefined;