Skip to content

fix: remove leaked NoteModel listener in NoteEditController#40

Merged
shukebeta merged 2 commits into
masterfrom
fix/issue-37-listener-leak-note-edit-controller
Jun 16, 2026
Merged

fix: remove leaked NoteModel listener in NoteEditController#40
shukebeta merged 2 commits into
masterfrom
fix/issue-37-listener-leak-note-edit-controller

Conversation

@shukebeta

Copy link
Copy Markdown
Owner

Summary

  • Extracts the anonymous listener in NoteEditController.initialize() to a named _syncControllerFromModel method so it can be removed in dispose()
  • Stores the NoteModel reference and calls removeListener before textController.dispose()
  • Guards the addPostFrameCallback body with _disposed to handle the race where dispose() runs before the frame callback fires

Test plan

  • flutter test test/controllers/note_edit_controller_test.dart — 12 tests pass (2 new regression tests added)
  • flutter analyze — no issues
  • New test: post-dispose setUploading(true/false) and setPasting(true/false) do not throw
  • New test: dispose-before-frame-callback path is a no-op

Closes #37

🤖 Generated with Claude Code

shukebeta and others added 2 commits June 16, 2026 20:32
The anonymous listener registered in initialize() via addPostFrameCallback
could not be removed, so any notifyListeners() call after the widget was
disposed (e.g. in-flight image upload completing post-navigation) would
write to an already-disposed TextEditingController.

Hoists the lambda to a named _syncControllerFromModel method, stores the
NoteModel reference, and removes the listener in dispose(). Guards the
addPostFrameCallback body with _disposed so that dispose-before-frame
races also produce a no-op.

Adds two regression tests covering the post-dispose and race paths.

Closes #37

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Add assert in initialize() to catch double-initialization in debug builds
- Null _noteModel in dispose() after removeListener to release the reference
- Fix weak test: setUploading(false) is a no-op when already false; call
  setUploading(true) first so notifyListeners() actually fires in the
  dispose-before-frame-callback test

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@shukebeta shukebeta merged commit 3b74654 into master Jun 16, 2026
3 checks passed
@shukebeta shukebeta deleted the fix/issue-37-listener-leak-note-edit-controller branch June 16, 2026 08:45
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.

defect: NoteEditController leaks a NoteModel listener; touches disposed TextEditingController after navigation

1 participant