Skip to content

Fix memory leaks in reader components#7

Merged
gvonness-apolitical merged 1 commit intomainfrom
fix/memory-leaks
Feb 1, 2026
Merged

Fix memory leaks in reader components#7
gvonness-apolitical merged 1 commit intomainfrom
fix/memory-leaks

Conversation

@gvonness-apolitical
Copy link
Copy Markdown
Collaborator

Summary

Memory leak audit identified and fixed 4 critical issues:

  • EPUB reader: Event listeners (keydown, relocate) were never removed
  • EPUB reader: Page change callback held references after destroy
  • Engine: Callbacks held closure references after destroy
  • ManifestController: Chapter cache grew unbounded with no eviction

Changes

EPUB Reader (src/readers/epub-reader.ts)

  • Store event handler references as instance variables
  • Remove keydown listener from document in destroy()
  • Remove relocate listener from view in destroy()
  • Nullify onPageChangeCallback in destroy()

Engine (src/core/engine.ts)

  • Nullify all callback references (onError, onPageChange, onChapterChange, onReady) in destroy()

ManifestController (src/core/manifest-controller.ts)

  • Implement LRU cache with max 5 chapters
  • Track chapter access order for proper eviction
  • Evict least recently used chapters when cache is full
  • Nullify callbacks in destroy()

Test plan

  • Build succeeds
  • Unit tests pass (32/32)
  • E2E tests pass (Chromium - 12/12)

- EPUB reader: Store and remove keydown and relocate event listeners in destroy()
- EPUB reader: Nullify onPageChangeCallback in destroy()
- Engine: Nullify all callback references in destroy()
- ManifestController: Implement LRU cache with max 5 chapters to prevent unbounded growth
- ManifestController: Nullify callbacks in destroy()
@gvonness-apolitical gvonness-apolitical merged commit 87429bf into main Feb 1, 2026
3 checks passed
@gvonness-apolitical gvonness-apolitical deleted the fix/memory-leaks branch February 1, 2026 21:47
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.

1 participant