vedang / pdf-tools

Emacs support library for PDF files.
https://pdftools.wiki
GNU General Public License v3.0
643 stars 90 forks source link

Image cache not cleared after closing pdf-buffer #215

Open emwal opened 1 year ago

emwal commented 1 year ago

Problem: Opening and reading pdfs sequentially fills up system memory.

Steps to reproduce:

  1. Open resource monitor and search the emacs process.
  2. Open pdf in emacs (with pdf-view-mode) and observe the increasing RAM usage when cycling pages.
  3. Kill Buffer with pdf.
  4. RAM usage stays the same.
  5. M-x memory-report shows big "total image cache size"

Fix: Eval (clear-image-cache) and the memory should return to normal.

It seems like, pdf-tools fails to call clear-image-cache when the active buffer is closed.

(Doom-)Emacs 28.2 pdf-tools installed via straight.el, commit "bc2ba117e8c3196ff9adf0da4fa1e63a8da3d7c8"

idlip commented 1 year ago

Yeah, i too have faced high memory usage, there is M-x pdf-cache-clear-data too.

I ended up making a function and i use it everywhere mapped to Q, in most of the reading buffers.

  (defun d/kill-buffer ()
    "Clear the image cache (to release memory) after killing a pdf buffer."
    (interactive)
    (if (one-window-p) (kill-this-buffer)
      (kill-buffer-and-window))
    (clear-image-cache)
    (pdf-cache-clear-data))

Hope that helps!

aikrahguzar commented 1 year ago

It seems like, pdf-tools fails to call clear-image-cache when the active buffer is closed.

Image cache is managed by Emacs and is cleared automatically. If you want to do it more aggressively, you can set a lower value for image-cache-eviction-delay.