Project

Profile

Help

Bug #6396

closed

Bug #6392: Memory leak in PySaxonProcessor (Python)

(Another?) memory leak when using XQuery?

Added by Martin Honnen 8 months ago. Updated 5 months ago.

Status:
Closed
Priority:
Normal
Category:
Python API
Start date:
2024-04-16
Due date:
% Done:

0%

Estimated time:
Applies to branch:
Fix Committed on Branch:
12
Fixed in Maintenance Release:
Found in version:
12.4.2
Fixed in version:
12.5
SaxonC Languages:
SaxonC Platforms:
SaxonC Architecture:

Description

Based on the recent bug reports on memory leaks with SaxonC I am looking into whether some of my use cases also show leaks, it appears that doing XQuery evaluation causes some memory leak, a test case

from saxonche import PySaxonProcessor
import psutil

xquery = """<items>
{
random-number-generator(current-dateTime())?permute(1 to 20) ! <item>item {.}</item>
}
</items>"""

count = 0
process = psutil.Process()
prev = process.memory_info().rss
print(f"{prev:,}")
print()

with PySaxonProcessor() as proc:

    xquery_processor = proc.new_xquery_processor()

    for _ in range(100):

        xquery_processor.run_query_to_value(query_text=xquery)

        if (count := count + 1) % 10 == 0:
            m = process.memory_info().rss
            print(f"{m - prev:,}")
            prev = m

print()
print(f"{prev:,}")

leaks on both Windows

26,062,848

6,111,232
1,302,528
1,302,528
1,306,624
1,298,432
1,302,528
1,306,624
1,310,720
1,298,432
1,302,528

43,905,024

and Linux

34,836,480

10,715,136
1,310,720
1,318,912
1,310,720
1,273,856
1,347,584
1,081,344
1,351,680
1,351,680
1,351,680

57,249,792

(Haven't tested on Mac).

Can't tell whether the XML creation in the XQuery leaks the same as the XML parsing in https://saxonica.plan.io/issues/6391, so I file this as a separate bug.

Please register to edit this issue

Also available in: Atom PDF