mupdf-js
mupdf-js copied to clipboard
Fixed memory leaks and added drawPageAsPNGRaw method
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.
Thanks @anthrax63 - I will review these changes and merge next week
@andytango Do you have any plans to merge in the near future? I am currently facing this issue as well?
@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);
- node :
v18.15.0