]> git.parisson.com Git - pdf.js.git/commitdiff
Tried to add a destroy function to free memeory, but doesn't seem to help
authorJulian Viereck <julian.viereck@gmail.com>
Fri, 16 Sep 2011 15:09:58 +0000 (08:09 -0700)
committerJulian Viereck <julian.viereck@gmail.com>
Fri, 16 Sep 2011 15:09:58 +0000 (08:09 -0700)
test/driver.js
worker.js

index d272aab69cba8596419fce50151788ef2ad3983b..79f94568b882efc21c1c3bb05b416a37a4c97e7e 100644 (file)
@@ -50,6 +50,11 @@ function load() {
 window.onload = load;
 
 function nextTask() {
+  // If there is a pdfDoc on the last task executed, destroy it to free memory.
+  if (task && task.pdfDoc) {
+    task.pdfDoc.destroy();
+    delete task.pdfDoc;
+  }
   if (currentTaskIdx == manifest.length) {
     return done();
   }
index eabdf66e3a028c8aa62203ffd53ea3d82e6ab98b..1a143c1d6ed11b484713094c8dc07a5415930b3d 100644 (file)
--- a/worker.js
+++ b/worker.js
@@ -182,7 +182,7 @@ var WorkerPDFDoc = (function() {
     var useWorker = true;
     
     if (useWorker) {
-      var worker = new Worker("../worker/boot_processor.js");
+      var worker = this.worker = new Worker("../worker/boot_processor.js");
     } else {
       // If we don't use a worker, just post/sendMessage to the main thread.
       var worker = {
@@ -262,6 +262,24 @@ var WorkerPDFDoc = (function() {
       
       var page = this.pdf.getPage(n);
       return this.pageCache[n] = new WorkerPage(this, page);
+    },
+    
+    destroy: function() {
+      console.log("destroy worker");
+      if (this.worker) {
+        this.worker.terminate();
+      }
+      if (this.fontWorker) {
+        this.fontWorker.terminate();
+      }
+      
+      for (var n in this.pageCache) {
+        delete this.pageCache[n];
+      }
+      delete this.data;
+      delete this.stream;
+      delete this.pdf;
+      delete this.catalog;
     }
   };