Skip to content

Commit

Permalink
Merge pull request #235 from Akxe/Memory_leak_fix#2
Browse files Browse the repository at this point in the history
Fix memory leak on component destroy
  • Loading branch information
codehippie1 authored Jan 2, 2024
2 parents 00cd641 + c914ed9 commit de283b3
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/src/ng2-pdfjs-viewer.component.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Component, Input, Output, OnInit, ViewChild, EventEmitter, ElementRef } from '@angular/core';
import { Component, Input, Output, OnInit, OnDestroy, ViewChild, EventEmitter, ElementRef } from '@angular/core';

@Component({
selector: 'ng2-pdfjs-viewer',
template: `<iframe title="ng2-pdfjs-viewer" [hidden]="externalWindow || (!externalWindow && !pdfSrc)" #iframe width="100%" height="100%"></iframe>`
})
export class PdfJsViewerComponent implements OnInit {
export class PdfJsViewerComponent implements OnInit, OnDestroy {
@ViewChild('iframe', { static: true }) iframe: ElementRef;
static lastID = 0;
@Input() public viewerId = `ng2-pdfjs-viewer-ID${++PdfJsViewerComponent.lastID}`;
Expand Down Expand Up @@ -341,4 +341,8 @@ export class PdfJsViewerComponent implements OnInit {
// pagemode = ${this.errorMessage}
// `);
}

ngOnDestroy(): void {
this.relaseUrl?.();
}
}

0 comments on commit de283b3

Please sign in to comment.