mupdf-js icon indicating copy to clipboard operation
mupdf-js copied to clipboard

Fixed memory leaks and added drawPageAsPNGRaw method

Open anthrax63 opened this issue 1 year ago • 2 comments

In my application, I have seen that the consumed process memory grows over time. As a result of research, I found that some methods allocate memory in C code that is never freed. This pull request solves this problem. Also method drawPageAsPNGRaw has been added, which immediately returns binary data. Also was fixed small issue - all methods returning strings had null byte at the end. Now this byte is truncated.

anthrax63 avatar Mar 29 '23 07:03 anthrax63

Thanks @anthrax63 - I will review these changes and merge next week

andytango avatar Jul 07 '23 07:07 andytango

@andytango Do you have any plans to merge in the near future? I am currently facing this issue as well? image

@anthrax63 when I use the package you published, I find that there are still memory leaks present

import { createMuPdfWithoutContext } from "@cahva/mupdf-js";
//const save2imgs =require("./libs/save2img.js");

(async () => {
  for (let i = 0; i < 5; i++) {
    const mupdf = await createMuPdfWithoutContext();
    const ctx = mupdf.createContext();
    const doc = mupdf.load(ctx, buf);

    console.log(mupdf.drawPageAsPNG(ctx, doc, 1, 300).length);
    mupdf.freeDocument(doc);
    mupdf.freeContext(ctx);
  }
})();

setInterval(() => {
   // mock something
}, 50000);

image
  • node : v18.15.0

rambo-panda avatar Aug 25 '23 15:08 rambo-panda