Memory-Leak with TextPage.search() (original) (raw)

Please provide all mandatory information!

Describe the bug (mandatory)

Using TextPage.search() leaks memory. This specific bug only appeared in 1.19.5

To Reproduce (mandatory)

Minimal Code-Snippet which makes leak obvious. Memory keeps increasing until process ends:

import fitz
from pathlib import Path

if name == 'main':
current_path = Path('placeholder.pdf')
search_text = 'placeholder'
for i in range(0, 10000):
with fitz.open(current_path) as pdf_file:
for page in pdf_file:
tp = page.get_textpage()
rlist = tp.search(search_text)

Expected behavior (optional)

tp.search() should free up memory after usage

Screenshots (optional)

Your configuration (mandatory)

For the first two Bullet-Points:
3.9.1 (tags/v3.9.1:1e5d33e, Dec 7 2020, 17:08:21) [MSC v.1927 64 bit (AMD64)]
win32

PyMuPDF 1.19.5: Python bindings for the MuPDF 1.19.0 library.
Version date: 2022-02-01 00:00:01.
Built for Python 3.9 on win32 (64-bit).

Built using pip (wheel)

Additional context (optional)