# Best Practices for managing memory in react

**URL:** <https://pdfjs.community/t/best-practices-for-managing-memory-in-react/3795>\
**Category:** Technical Support\
**Created:** [September 10, 2025, 1:39am UTC](https://pdfjs.community/t/best-practices-for-managing-memory-in-react/3795 "2025-09-10T01:39:41Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dale](https://avatars.discourse-cdn.com/v4/letter/d/ecd19e/32.png) [@dale](https://pdfjs.community/u/dale)\
**Post date:** [September 10, 2025, 1:39am UTC](https://pdfjs.community/t/best-practices-for-managing-memory-in-react/3795/1 "2025-09-10T01:39:41Z")

</div>

Using PDFJS Webviewer in React, what are some tips/best practices for managing memory when dealing with a single webviewer and multiple pdf documents.

Currently our memory usage grows with each document switch, even if returning to a document that had already been loaded.

---

<div class="post-metadata">

**Author:** ![kkim](https://avatars.discourse-cdn.com/v4/letter/k/3ab097/32.png) [@kkim](https://pdfjs.community/u/kkim)\
**Post date:** [September 10, 2025, 5:02pm UTC](https://pdfjs.community/t/best-practices-for-managing-memory-in-react/3795/3 "2025-09-10T17:02:08Z")

</div>

Hi there,

We recommend using the loadDocument API to open every new document with the same instance.

Please see this guide for more details:

> **[PDF.js Express Viewer Integration Best Practices | Documentation](https://pdfjs.express/documentation/learn-more/best-practices)**

Best regards,

Kevin

---

<div class="post-metadata">

**Author:** ![dale](https://avatars.discourse-cdn.com/v4/letter/d/ecd19e/32.png) [@dale](https://pdfjs.community/u/dale)\
**Post date:** [September 11, 2025, 7:14am UTC](https://pdfjs.community/t/best-practices-for-managing-memory-in-react/3795/4 "2025-09-11T07:14:32Z")

</div>

I’ve followed those where appropriate, but wondering how else to prevent memory from growing.

---

<div class="post-metadata">

**Author:** ![kkim](https://avatars.discourse-cdn.com/v4/letter/k/3ab097/32.png) [@kkim](https://pdfjs.community/u/kkim)\
**Post date:** [September 11, 2025, 1:57pm UTC](https://pdfjs.community/t/best-practices-for-managing-memory-in-react/3795/5 "2025-09-11T13:57:27Z")

</div>

Hi there,

There is a dispose method under the UI namespace that you could try using, if it is not happening automatically:

> **[PDFJS Express WebViewer Namespace: UI](https://pdfjs.express/api/UI.html#.dispose__anchor)**

best regards,

Kevin
