Tried to add a destroy function to free memeory, but doesn't seem to help

This commit is contained in:
Julian Viereck 2011-09-16 08:09:58 -07:00
parent 20d8a13c9e
commit 921f8bd669
2 changed files with 24 additions and 1 deletions

View file

@ -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;
}
};