Skip to content

fix(interfaces): apply Intentional Leak pattern to GlobalLoggerRegistry#201

Merged
kcenon merged 2 commits into
mainfrom
fix/intentional-leak-global-logger-registry-200
Dec 15, 2025
Merged

fix(interfaces): apply Intentional Leak pattern to GlobalLoggerRegistry#201
kcenon merged 2 commits into
mainfrom
fix/intentional-leak-global-logger-registry-200

Conversation

@kcenon

@kcenon kcenon commented Dec 15, 2025

Copy link
Copy Markdown
Owner

Summary

  • Apply Intentional Leak pattern to GlobalLoggerRegistry::instance() and null_logger() to prevent Static Destruction Order Fiasco (SDOF)
  • Update singleton guidelines documentation with resolved status and current implementation details

Changes

Code Changes

  • GlobalLoggerRegistry::instance(): Changed from Meyer's Singleton to heap-allocated pointer that is never deleted
  • null_logger(): Changed from static local to heap-allocated shared_ptr<NullLogger>
  • Added documentation comments explaining the pattern choice

Documentation Updates

  • Updated SINGLETON_GUIDELINES.md and SINGLETON_GUIDELINES_KO.md
  • Marked GlobalLoggerRegistry as resolved in audit results table
  • Updated detailed analysis section with current implementation

Rationale

The registry and null logger may be accessed during other static objects' destruction (e.g., when thread_context logs during thread_pool destruction). The Intentional Leak pattern ensures these objects remain valid throughout the entire process lifetime.

Memory impact is minimal (~200 bytes for registry + ~32 bytes for null_logger) and is reclaimed by the OS at process termination.

Test plan

  • All 104 existing tests pass
  • Build succeeds without warnings
  • No behavioral changes (API remains identical)

Fixes #200

Apply Intentional Leak pattern to GlobalLoggerRegistry::instance() and
null_logger() static methods to prevent Static Destruction Order Fiasco
(SDOF).

Changes:
- Change instance() to use heap-allocated pointer that is never deleted
- Change null_logger() to use heap-allocated shared_ptr
- Add documentation comments explaining the pattern choice

The registry and null logger may be accessed during other static objects'
destruction, so they must remain valid throughout the entire process
lifetime. The leaked memory is minimal (~few hundred bytes) and is
reclaimed by the OS at process termination.

Fixes #200
Update SINGLETON_GUIDELINES.md and SINGLETON_GUIDELINES_KO.md to reflect
that GlobalLoggerRegistry now uses the Intentional Leak pattern.

Changes:
- Update audit results table with new pattern and resolved status
- Update detailed analysis section with current implementation
- Add memory impact information
@kcenon kcenon merged commit edf7bde into main Dec 15, 2025
19 checks passed
@kcenon kcenon deleted the fix/intentional-leak-global-logger-registry-200 branch December 15, 2025 06:33
kcenon added a commit that referenced this pull request Apr 13, 2026
…ry (#201)

* fix(interfaces): apply Intentional Leak pattern to GlobalLoggerRegistry

Apply Intentional Leak pattern to GlobalLoggerRegistry::instance() and
null_logger() static methods to prevent Static Destruction Order Fiasco
(SDOF).

Changes:
- Change instance() to use heap-allocated pointer that is never deleted
- Change null_logger() to use heap-allocated shared_ptr
- Add documentation comments explaining the pattern choice

The registry and null logger may be accessed during other static objects'
destruction, so they must remain valid throughout the entire process
lifetime. The leaked memory is minimal (~few hundred bytes) and is
reclaimed by the OS at process termination.

Fixes #200

* docs: update singleton guidelines for GlobalLoggerRegistry #200

Update SINGLETON_GUIDELINES.md and SINGLETON_GUIDELINES_KO.md to reflect
that GlobalLoggerRegistry now uses the Intentional Leak pattern.

Changes:
- Update audit results table with new pattern and resolved status
- Update detailed analysis section with current implementation
- Add memory impact information
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.

fix: apply Intentional Leak pattern to GlobalLoggerRegistry for SDOF prevention

1 participant