[PR #3761] Fix DI memory leak #9681

Closed
opened 2026-02-07 06:06:37 +03:00 by OVERLORD · 0 comments
Owner

Original Pull Request: https://github.com/jellyfin/jellyfin/pull/3761

State: closed
Merged: Yes


Changes
Removed JellyfinDb from the DI container for now. Registering Transient instances that implement IDisposable and then using them in the root scope is a big no-no. They will never be GC'd until the container or scope is disposed, which will only happen on shutdown.

An alternative solution is to create a Scope whenever we need the context, but the factory pattern is cleaner.

DISCLAIMER: I haven't actually been able to reproduce the leak, but based on memory snapshots and research it seems like the most likely scenario.

Sources:

Issues
Fixes #3680

**Original Pull Request:** https://github.com/jellyfin/jellyfin/pull/3761 **State:** closed **Merged:** Yes --- <!-- Ensure your title is short, descriptive, and in the imperative mood (Fix X, Change Y, instead of Fixed X, Changed Y). For a good inspiration of what to write in commit messages and PRs please review https://chris.beams.io/posts/git-commit/ and our documentation. --> **Changes** Removed `JellyfinDb` from the DI container for now. Registering Transient instances that implement IDisposable and then using them in the root scope is a big no-no. They will never be GC'd until the container or scope is disposed, which will only happen on shutdown. An alternative solution is to create a Scope whenever we need the context, but the factory pattern is cleaner. **DISCLAIMER**: I haven't actually been able to reproduce the leak, but based on memory snapshots and research it seems like the most likely scenario. Sources: - https://github.com/aspnet/DependencyInjection/issues/456 - https://github.com/dotnet/runtime/issues/36491 - https://docs.microsoft.com/en-us/aspnet/core/fundamentals/dependency-injection?view=aspnetcore-3.1#idisposable-guidance-for-transient-and-shared-instances **Issues** Fixes #3680
OVERLORD added the pull-request label 2026-02-07 06:06:37 +03:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/jellyfin#9681