I am using wand and pytesseract to get the text of pdfs uploaded to a django website like so:
image_pdf = Image(blob=read_pdf_file, resolution=300)
image_png
I was also suffering from memory leaks issues. After some research and tweaking the code implementation, my issues were resolved. I basically worked correctly using with and destroy() function.
In some cases I could use with to open and read the files, as in the example below:
with Image(filename = pdf_file, resolution = 300) as pdf:
This case, using with, the memory and tmp files are correctly managed.
And in another case I had to use the destroy() function, preferably inside a try / finally block, as below:
try:
for img in pdfImg.sequence:
# your code
finally:
pdfImg.destroy()
The second case, is an example where I cann't use with because I had to iterate the pages through the sequence, so, I already had the file open and was iterating your pages.
This conbination of solution resolved my problems with memory leaks.