Skip to content

fix: release image backend resources after frame extraction#3134

Merged
PeterStaar-IBM merged 1 commit intodocling-project:mainfrom
LarytheLord:fix/image-backend-close-3133
Mar 16, 2026
Merged

fix: release image backend resources after frame extraction#3134
PeterStaar-IBM merged 1 commit intodocling-project:mainfrom
LarytheLord:fix/image-backend-close-3133

Conversation

@LarytheLord
Copy link
Copy Markdown
Contributor

Issue resolved by this Pull Request:
Resolves #3133

This updates ImageDocumentBackend to release image resources more explicitly after eager frame extraction:

  • open the source image with a context manager so the original PIL handle is closed once frames are copied
  • close any partially created frames if backend initialization fails
  • close cached frame images during backend unload instead of only dropping references

It also adds regression coverage for the source-image close path and for frame cleanup during unload.

Checklist:

  • Documentation has been updated, if necessary.
  • Examples have been added, if necessary.
  • Tests have been added, if necessary.

@github-actions
Copy link
Copy Markdown
Contributor

DCO Check Passed

Thanks @LarytheLord, all your commits are properly signed off. 🎉

@mergify
Copy link
Copy Markdown
Contributor

mergify bot commented Mar 15, 2026

Merge Protections

Your pull request matches the following merge protections and will not be merged until they are valid.

🟢 Enforce conventional commit

Wonderful, this rule succeeded.

Make sure that we follow https://www.conventionalcommits.org/en/v1.0.0/

  • title ~= ^(fix|feat|docs|style|refactor|perf|test|build|ci|chore|revert)(?:\(.+\))?(!)?:

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 16, 2026

Codecov Report

❌ Patch coverage is 80.00000% with 3 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
docling/backend/image_backend.py 80.00% 3 Missing ⚠️

📢 Thoughts on this report? Let us know!

Copy link
Copy Markdown
Member

@PeterStaar-IBM PeterStaar-IBM left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm!

@PeterStaar-IBM PeterStaar-IBM merged commit 1e841eb into docling-project:main Mar 16, 2026
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Memory leak in image_backend (forgotten Image.open())

2 participants