Project

Profile

Help

Bug #6392

closed

Memory leak in PySaxonProcessor (Python)

Added by Andy Knight 8 months ago. Updated 5 months ago.

Status:
Closed
Priority:
Normal
Category:
-
Start date:
2024-04-14
Due date:
% Done:

100%

Estimated time:
(Total: 0:00 h)
Applies to branch:
Fix Committed on Branch:
12
Fixed in Maintenance Release:
Found in version:
Fixed in version:
12.5
SaxonC Languages:
SaxonC Platforms:
SaxonC Architecture:

Description

Consider the following code fragment:

from saxonche import PySaxonProcessor import psutil

count = 0 prev = (mi := psutil.Process().memory_info)().rss

for _ in range(100): with PySaxonProcessor(license=False): pass if (count := count + 1) % 10 == 0: m = mi().rss print(f"{m - prev:,}") prev = m

It can be observed that memory usage increases over time. The exit functionality of the PySaxonProcessor class is not "cleaning up" as robustly as it should.

Python 3.12.2 saxonche 12.4.2 macOS 14.4.1 M2


Sub-issues 4 (0 open4 closed)

Bug #6391: Possible memory leak in Python processor?ClosedMatt Patterson2024-04-14

Actions
Bug #6396: (Another?) memory leak when using XQuery?ClosedO'Neil Delpratt2024-04-16

Actions
Bug #6397: Another? memory leak when using XPathClosedO'Neil Delpratt2024-04-16

Actions
Bug #6398: Another? memory leak when using XSLTClosedMatt Patterson2024-04-16

Actions
Actions #1

Updated by Andy Knight 8 months ago

Apologies for incorrect code formatting in initial submission:

from saxonche import PySaxonProcessor
import psutil

count = 0
prev = (mi := psutil.Process().memory_info)().rss

for _ in range(100):
    with PySaxonProcessor(license=False):
        pass
    if (count := count + 1) % 10 == 0:
        m = mi().rss
        print(f"{m - prev:,}")
        prev = m
Actions #2

Updated by O'Neil Delpratt 8 months ago

  • Project changed from Saxon-CE to SaxonC

Moving this project to the SaxonC project

Actions #3

Updated by Matt Patterson 8 months ago

  • Status changed from New to In Progress
  • Assignee set to Matt Patterson
Actions #4

Updated by Matt Patterson 6 months ago

  • Status changed from In Progress to Resolved
  • Fixed in version set to 12.5.0

This has been a bit tricky to track down, largely because it looks like we had fixed it as a side-effect of making more general changes after 12.4.2 released, and before this was reported.

After more extensive testing using memray and a debug-enabled build, I can't see any evidence of memory leaks in the current build, which I was able to see when build a debug-enabled version of 12.4.

It's worth noting that, depending on system memory constraints, and other environmental factors, running this example for a large number of iterations may not result in the RSS usage of the process stabilising. On my machine, I've been finding it needs thousands of iterations before the OS starts reclaiming some of the assigned-but-unused memory, but memray reveals that heap usage has settled, is constant and not increasing.

Because of the similarity of this to a number of memory-related issues that were opened, I'm going to mark the others as children of this issue...

Actions #5

Updated by O'Neil Delpratt 5 months ago

  • Status changed from Resolved to Closed
  • Fixed in version changed from 12.5.0 to 12.5

Bug fix applied in the Saxon 12.5 Maintenance release.

Actions #6

Updated by Community Admin 5 months ago

  • Fix Committed on Branch 12 added

Please register to edit this issue

Also available in: Atom PDF