diff --git a/addon/chrome/content/previewPDF.html b/addon/chrome/content/previewPDF.html
index c1f67fa..f35e87d 100644
--- a/addon/chrome/content/previewPDF.html
+++ b/addon/chrome/content/previewPDF.html
@@ -94,7 +94,10 @@
console.log(e);
if (e.data.type === "renderPreview") {
if (itemID !== e.data.itemID) {
+ // Destroy worker to avoid memory leak
+ pdf && pdf.destroy();
pdf = await pdfjsLib.getDocument(e.data.buffer).promise;
+ delete e.data.buffer;
itemID = e.data.itemID;
}
renderPreview(e.data.itemID, e.data.width);