Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor removing of the zoomLayer into a helper method, and use that in PDFPageView.reset to ensure that the entire zoomLayer is actually removed (issue 8209) #8210

Merged
merged 1 commit into from
Mar 30, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 32 additions & 25 deletions web/pdf_page_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,33 @@ var PDFPageView = (function PDFPageViewClosure() {
},

destroy: function PDFPageView_destroy() {
this.zoomLayer = null;
this.reset();
if (this.pdfPage) {
this.pdfPage.cleanup();
}
},

/**
* @private
*/
_resetZoomLayer: function(removeFromDOM) {
if (!this.zoomLayer) {
return;
}
var zoomLayerCanvas = this.zoomLayer.firstChild;
this.paintedViewportMap.delete(zoomLayerCanvas);
// Zeroing the width and height causes Firefox to release graphics
// resources immediately, which can greatly reduce memory consumption.
zoomLayerCanvas.width = 0;
zoomLayerCanvas.height = 0;

if (removeFromDOM) {
// Note: ChildNode.remove doesn't throw if the parentNode is undefined.
this.zoomLayer.remove();
}
this.zoomLayer = null;
},

reset: function PDFPageView_reset(keepZoomLayer, keepAnnotations) {
this.cancelRendering();

Expand Down Expand Up @@ -168,13 +188,16 @@ var PDFPageView = (function PDFPageViewClosure() {
this.annotationLayer = null;
}

if (this.canvas && !currentZoomLayerNode) {
this.paintedViewportMap.delete(this.canvas);
// Zeroing the width and height causes Firefox to release graphics
// resources immediately, which can greatly reduce memory consumption.
this.canvas.width = 0;
this.canvas.height = 0;
delete this.canvas;
if (!currentZoomLayerNode) {
if (this.canvas) {
this.paintedViewportMap.delete(this.canvas);
// Zeroing the width and height causes Firefox to release graphics
// resources immediately, which can greatly reduce memory consumption.
this.canvas.width = 0;
this.canvas.height = 0;
delete this.canvas;
}
this._resetZoomLayer();
}
if (this.svg) {
this.paintedViewportMap.delete(this.svg);
Expand Down Expand Up @@ -429,23 +452,7 @@ var PDFPageView = (function PDFPageViewClosure() {
div.removeChild(self.loadingIconDiv);
delete self.loadingIconDiv;
}

if (self.zoomLayer) {
var zoomLayerCanvas = self.zoomLayer.firstChild;
self.paintedViewportMap.delete(zoomLayerCanvas);
// Zeroing the width and height causes Firefox to release graphics
// resources immediately, which can greatly reduce memory consumption.
zoomLayerCanvas.width = 0;
zoomLayerCanvas.height = 0;

if (div.contains(self.zoomLayer)) {
// Prevent "Node was not found" errors if the `zoomLayer` was
// already removed. This may occur intermittently if the scale
// changes many times in very quick succession.
div.removeChild(self.zoomLayer);
}
self.zoomLayer = null;
}
self._resetZoomLayer(/* removeFromDOM = */ true);

self.error = error;
self.stats = pdfPage.stats;
Expand Down