Skip to content

Memory Management: Dispose IDisposable resources correctly in four internal classes#22014

Merged
Migaroez merged 5 commits intomainfrom
v17/bugfix/plug-potential-memory-leaks
Mar 5, 2026
Merged

Memory Management: Dispose IDisposable resources correctly in four internal classes#22014
Migaroez merged 5 commits intomainfrom
v17/bugfix/plug-potential-memory-leaks

Conversation

@AndyButland
Copy link
Copy Markdown
Contributor

@AndyButland AndyButland commented Mar 4, 2026

Description

Housekeeping PR that ensures four internal IDisposable resources are disposed correctly, in line with .NET best practices.

None of these are suspected to cause real-world problems. The disposed objects are either short-lived, cleaned up at shutdown, or finalized by the GC eventually. However, they are violations of the IDisposable contract and worth fixing for code hygiene.

Testing

Visual inspection will suffice here.

Copilot AI review requested due to automatic review settings March 4, 2026 14:48
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Housekeeping changes to tighten IDisposable ownership/cleanup in internal infrastructure and dev-mode components, aligning resource lifetimes with .NET disposal best practices.

Changes:

  • Dispose CancellationTokenSource in DatabaseServerMessenger’s dispose path.
  • Dispose JsonDocument after deserializing cache refresh instructions in CacheInstructionService.
  • Ensure cryptography primitives (ICryptoTransform, CryptoStream) are disposed in legacy password decryption.
  • Make InMemoryAssemblyLoadContextManager disposable to unsubscribe from AssemblyLoadContext.Default.Resolving.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
src/Umbraco.Infrastructure/Sync/DatabaseServerMessenger.cs Disposes the internal CancellationTokenSource during managed disposal.
src/Umbraco.Infrastructure/Services/CacheInstructionService.cs Adds disposal of JsonDocument after instruction extraction.
src/Umbraco.Infrastructure/Security/MemberPasswordHasher.cs Scopes crypto resources with using to ensure deterministic cleanup.
src/Umbraco.Cms.DevelopmentMode.Backoffice/InMemoryAuto/InMemoryAssemblyLoadContextManager.cs Implements IDisposable to unsubscribe the default ALC resolving handler.

@AndyButland AndyButland changed the title Housekeeping: Dispose IDisposable resources correctly in four internal classes Housekeeping: Dispose IDisposable resources correctly in four internal classes Mar 4, 2026
@AndyButland AndyButland changed the title Housekeeping: Dispose IDisposable resources correctly in four internal classes Memory Management: Dispose IDisposable resources correctly in four internal classes Mar 4, 2026
Copy link
Copy Markdown
Contributor

@Migaroez Migaroez left a comment

Choose a reason for hiding this comment

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

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants