# Huge memory leak - React

**URL:** <https://pdfjs.community/t/huge-memory-leak-react/2577>\
**Category:** Bug Reports\
**Created:** [May 12, 2023, 12:49pm UTC](https://pdfjs.community/t/huge-memory-leak-react/2577 "2023-05-12T12:49:42Z")\
**Posts on this page:** 7\
**Page:** 2

<div class="post-metadata">

**Author:** ![CarlosVergikosk](https://avatars.discourse-cdn.com/v4/letter/c/5daacb/32.png) [@CarlosVergikosk](https://pdfjs.community/u/CarlosVergikosk)\
**Post date:** [June 27, 2023, 11:46am UTC](https://pdfjs.community/t/huge-memory-leak-react/2577/22 "2023-06-27T11:46:46Z")

</div>

Sure, here it is. @tgordon

You can open and close the modals multiple times to see your memory mounting until crashing.

[Codesandbox](https://codesandbox.io/p/github/CarlosVergikosk/wonderful-ben-9d7dm2/main?layout=%257B%2522sidebarPanel%2522%253A%2522EXPLORER%2522%252C%2522rootPanelGroup%2522%253A%257B%2522direction%2522%253A%2522horizontal%2522%252C%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522id%2522%253A%2522ROOT_LAYOUT%2522%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522direction%2522%253A%2522horizontal%2522%252C%2522id%2522%253A%2522EDITOR%2522%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL%2522%252C%2522panelType%2522%253A%2522TABS%2522%252C%2522id%2522%253A%2522clje3ypoo00j92v6mykqowm2z%2522%257D%255D%252C%2522sizes%2522%253A%255B100%255D%257D%252C%257B%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522direction%2522%253A%2522horizontal%2522%252C%2522id%2522%253A%2522DEVTOOLS%2522%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL%2522%252C%2522panelType%2522%253A%2522TABS%2522%252C%2522id%2522%253A%2522clje3v4s9000d2v6mz9d2vj15%2522%257D%255D%252C%2522sizes%2522%253A%255B100%255D%257D%255D%252C%2522sizes%2522%253A%255B50%252C50%255D%257D%252C%2522tabbedPanels%2522%253A%257B%2522clje3ypoo00j92v6mykqowm2z%2522%253A%257B%2522id%2522%253A%2522clje3ypoo00j92v6mykqowm2z%2522%252C%2522activeTabId%2522%253A%2522clje407hc00wz2v6mwlohba6t%2522%252C%2522tabs%2522%253A%255B%257B%2522type%2522%253A%2522FILE%2522%252C%2522filepath%2522%253A%2522%252Fsrc%252Fcomponents%252FPDFViewer.tsx%2522%252C%2522id%2522%253A%2522clje407hc00wz2v6mwlohba6t%2522%252C%2522mode%2522%253A%2522permanent%2522%252C%2522state%2522%253A%2522IDLE%2522%257D%252C%257B%2522type%2522%253A%2522FILE%2522%252C%2522filepath%2522%253A%2522%252Fpackage.json%2522%252C%2522id%2522%253A%2522clje4h40t00ll2v6serzgqx73%2522%252C%2522mode%2522%253A%2522temporary%2522%252C%2522state%2522%253A%2522IDLE%2522%257D%255D%257D%252C%2522clje3v4s9000d2v6mz9d2vj15%2522%253A%257B%2522id%2522%253A%2522clje3v4s9000d2v6mz9d2vj15%2522%252C%2522tabs%2522%253A%255B%257B%2522id%2522%253A%2522clje4lfmi01bv2v6ssrf9rzn8%2522%252C%2522mode%2522%253A%2522permanent%2522%252C%2522type%2522%253A%2522TASK_PORT%2522%252C%2522port%2522%253A5173%252C%2522taskId%2522%253A%2522dev%2522%252C%2522path%2522%253A%2522%252F%2522%257D%252C%257B%2522type%2522%253A%2522TASK_LOG%2522%252C%2522taskId%2522%253A%2522dev%2522%252C%2522id%2522%253A%2522clje4sl9300bj2v6nlr8iwh3w%2522%252C%2522mode%2522%253A%2522permanent%2522%257D%255D%252C%2522activeTabId%2522%253A%2522clje4lfmi01bv2v6ssrf9rzn8%2522%257D%257D%252C%2522showDevtools%2522%253Atrue%252C%2522showSidebar%2522%253Atrue%252C%2522sidebarPanelSize%2522%253A15%257D)

---

<div class="post-metadata">

**Author:** ![CarlosVergikosk](https://avatars.discourse-cdn.com/v4/letter/c/5daacb/32.png) [@CarlosVergikosk](https://pdfjs.community/u/CarlosVergikosk)\
**Post date:** [July 5, 2023, 1:42pm UTC](https://pdfjs.community/t/huge-memory-leak-react/2577/23 "2023-07-05T13:42:13Z")

</div>

@tgordon any news?

This is still an issue for us.

---

<div class="post-metadata">

**Author:** ![tgordon](https://avatars.discourse-cdn.com/v4/letter/t/aca169/32.png) [@tgordon](https://pdfjs.community/u/tgordon)\
**Post date:** [July 10, 2023, 11:19pm UTC](https://pdfjs.community/t/huge-memory-leak-react/2577/24 "2023-07-10T23:19:26Z")

</div>

Hey CarlosVergikosk,

Apologies for the delay, and thank you for the sample.

I think it’s important to note from the sample, you’re not actually calling the dispose when you’re closing the modal. The usage of memorization and useCallback (which includes caching) is also troublesome in this case as well (although I cant pinpoint if this is the reason why)

I suggest you modify the app to actually close WebViewer on modal close, instead when instantiating a new WebViewer.

Best regards,  
Tyler

---

<div class="post-metadata">

**Author:** ![CarlosVergikosk](https://avatars.discourse-cdn.com/v4/letter/c/5daacb/32.png) [@CarlosVergikosk](https://pdfjs.community/u/CarlosVergikosk)\
**Post date:** [November 30, 2023, 10:59am UTC](https://pdfjs.community/t/huge-memory-leak-react/2577/25 "2023-11-30T10:59:05Z")

</div>

Hi @tgordon, after speaking with Apryse directly, we managed to identify that there is indeed a memory leak on their premium viewer and subsequentially on this too.

It can only be reproduced if you have browser extensions that interfere with the DOM and prevent garbage collection from the viewers.

Maybe that’s why you couldn’t reproduce it.

sandbox: [https://github.com/jgozner/webviewer-sandbo](https://github.com/jgozner/webviewer-sandbox)

Install an extension like Grammarly, and you will reproduce it.  
I hope this helps people in the same situation, and that you can pump it on your team so this can get fixed asap.

@tgordon

---

<div class="post-metadata">

**Author:** ![slouis](https://avatars.discourse-cdn.com/v4/letter/s/898d66/32.png) [@slouis](https://pdfjs.community/u/slouis)\
**Post date:** [December 28, 2023, 6:04am UTC](https://pdfjs.community/t/huge-memory-leak-react/2577/26 "2023-12-28T06:04:47Z")

</div>

Are there any updates on this issue. I believe that I may have encoutered the same memory leak issue despite using the `dispose` calls.

---

<div class="post-metadata">

**Author:** ![CarlosVergikosk](https://avatars.discourse-cdn.com/v4/letter/c/5daacb/32.png) [@CarlosVergikosk](https://pdfjs.community/u/CarlosVergikosk)\
**Post date:** [December 31, 2023, 1:03pm UTC](https://pdfjs.community/t/huge-memory-leak-react/2577/27 "2023-12-31T13:03:31Z")

</div>

@slouis

I spoke with people from Apryse directly, and they admitted that there is indeed a memory leak issue when you have an extension like Grammarly installed that prevents their viewer from cleaning its instances correctly.

Since no one seemed to care about this issue, we had to search for other solutions to render PDFs. I can recommend using [Adobe PDF Embed API](https://developer.adobe.com/document-services/docs/overview/pdf-embed-api/).

---

<div class="post-metadata">

**Author:** ![5nicky](https://avatars.discourse-cdn.com/v4/letter/5/ba9def/32.png) [@5nicky](https://pdfjs.community/u/5nicky)\
**Post date:** [June 28, 2025, 5:06am UTC](https://pdfjs.community/t/huge-memory-leak-react/2577/28 "2025-06-28T05:06:55Z")

</div>

Hello there,

i am facing the same issue, opening the viewer in an incognito tab fixes the issue since extensions are disabled. it has been almost 2 years and apryse still hasn’t fixed it. i am using the CommonJS module not the React one and the issue seems to be still persistent. anybody found a fix yet? @tgordon

~ Erik

[Previous page](https://pdfjs.community/t/huge-memory-leak-react/2577.md?page=1)
