-
Notifications
You must be signed in to change notification settings - Fork 510
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
insertpdf to merge multiple pdf into one pdf, but test memory leak. #669
Comments
i used memory-pix.py in #389,
|
Thanks for reporting this. |
i have viewed the latest mupdf source code, page_merge.c(mupdf/source/tools/pdfmerge.c), pdf-graft.c(mupdf/source/pdf/pdf-graft.c): Lines 510 to 513 in 9b07a4b
fz_always(ctx) {
pdf_drop_obj(ctx, obj);
pdf_drop_obj(ctx, page_dict);
pdf_drop_obj(ctx, ref);
} and drop pdf_obj *o(when copy_annots). i build my pymupdf with swig, insertPdf memory leak decreased. then i test with code like this,(delete insertPdf method): import gc
import psutil
import fitz
try:
TOOLS = fitz.TOOLS
except:
TOOLS = fitz.Tools()
gc.set_debug(gc.DEBUG_UNCOLLECTABLE)
pdf_path_list = ["input_1.pdf", "input_2.pdf", ...., "input_33.pdf"]
for i in range(1000):
process = psutil.Process(os.getpid())
for j in range(len(pdf_path_list)):
page_start_memory = process.memory_info().rss / 2 ** 10
sub_doc = fitz.open(pdf_path_list[j])
sub_doc.close()
page_end_memory = process.memory_info().rss / 2 ** 10
increase = int(page_end_memory - page_start_memory)
TOOLS.store_shrink(100) # reset MuPDF global context
gc.collect()
print("i:{},j:{},increase memory:{}kb".format(i, j, increase))
time.sleep(1) after serveral loop times, it increases indeed(with no decrease when program running):
Is this normal?maybe there is some global variables not released. |
You put your finger exactly in the wound, chapeau!
So I guess we have to leave it like that, if we do not see other spots in PyMuPDF
|
ok,thanks for your input,i will try it. |
This issue is fixed with v1.18.0 - at least for the major part. |
Describe the bug
insertPDF cause a memory leak
To Reproduce (mandatory)
i test the following code in a docker container:
when i tested ,the docker container memory usage increase from 96MB to 300MB, and then 400MB.
is there a memoy leak?
Your configuration (mandatory)
sys version and platform are as follows:
The text was updated successfully, but these errors were encountered: