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

"Total canvas memory use exceeds the maximum limit (256 MB)" error in safari 12 and above #11297

Closed
mobiusy opened this issue Nov 1, 2019 · 12 comments

Comments

@mobiusy
Copy link

mobiusy commented Nov 1, 2019

All PDF files have this issue.
PD216484A.pdf

Configuration:

  • safari 12
  • iPad (6th generation), system version: 12.1.4
  • PDF.js version: 1.6.0

Steps to reproduce the problem:

  1. Prepare one pdf file, more pages more better
  2. Open safari and open pdf file via pdf.js
  3. Do not close the tab, open an new tab and open the pdf file in same way
  4. Repeat step 3 until the pdf file pages shows blank

image

What is the expected behavior?
Expected the pdf shows correctly event user do not close previous tab.

What went wrong?
Got errors in browser inspector:
image

More info:

  1. I tried the latest version of pdf.js(2.3.200), this issue still exists.
  2. IPAD OS 13 have the same issue.

Is this a safari bug or pdf.js has workaround to avoid blank pages?

@Snuffleupagus
Copy link
Collaborator

Duplicate of #11245.

PDF.js version: 1.6.0

Furthermore, that's not an official release and in any case that version is a few years old and consequently no longer supported.

@mobiusy
Copy link
Author

mobiusy commented Nov 1, 2019

Duplicate of #11245.

PDF.js version: 1.6.0

Furthermore, that's not an official release and in any case that version is a few years old and consequently no longer supported.

I replaced the old version with 2.3.200, and apply the fix of fix of 11245, the issue still exists.
I think it is not the same reason with #11245 , but it exceed the memory usage limit of safari browser on iPad OS.

@timvandermeij
Copy link
Contributor

2.3.200 also doesn't contain the fix from that issue yet. I would suggest waiting for the next release or cherry-picking the fix if need be. Closing since this should be fixed then.

@mobiusy
Copy link
Author

mobiusy commented Nov 2, 2019

2.3.200 also doesn't contain the fix from that issue yet. I would suggest waiting for the next release or cherry-picking the fix if need be. Closing since this should be fixed then.

Thanks for your reply. I applied the fix of 11245 in 2.3.200, and my issue is not been fixed. On iPad OS 12.1.4, the isIOS() check works OK before the fix, userAgent match the /IPAD/ check. I appreciate if you can do more investigation.

@Stevebel
Copy link

Stevebel commented Dec 20, 2019

I was having a similar issue when I embedded the viewer in my app. There is a known issue with Safari that prevents garbage collection of canvases.

There's already code in place that has a workaround to force memory to clear when scrolling through the PDF (PDFPageView.reset):

pdf.js/web/pdf_page_view.js

Lines 185 to 188 in 693240c

// 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;

However, this code wasn't being run when I closed the viewer, so I added the following code before closing the viewer:

PDFViewerApplication.pdfViewer._pages.forEach(page => page.reset());

I don't have enough experience with this project to know if there are any edge cases where this causes issues, but in our testing nothing has come up and we no longer have a memory leak.

@Th3Fire
Copy link

Th3Fire commented May 15, 2020

const DEFAULT_CACHE_SIZE = 10;

I workaround by reduce DEFAULT_CACHE_SIZE which number less than 10.
Hope this will help whom facing this problem.

@seopei
Copy link

seopei commented Jun 28, 2020

I am running into the same issue. Is there a fix available? I am using ng2-pdf-viewer (VadimDez/ng2-pdf-viewer#492)

@visuallization
Copy link

We run into the same issue on IOS Safari. @mobiusy did you find a way to solve it?

@mobiusy
Copy link
Author

mobiusy commented Dec 1, 2021

We run into the same issue on IOS Safari. @mobiusy did you find a way to solve it?
Not yet, hope safari can fix this issue

@kantsverma
Copy link

kantsverma commented Dec 28, 2021

I am facing the same issues with IOS 15.1 in iPhone and Mac

Check detail over here

@jcsrb
Copy link

jcsrb commented Mar 31, 2022

@Snuffleupagus
Copy link
Collaborator

Given that we (obviously) cannot fix canvas-related memory handling problems in the Safari browser itself, and that Firefox is the primary development target for this library, let's close this old issue since it unfortunately doesn't really seem actionable here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants