Skip to content

Fix memory leak: use weak self in timeline observation loop#96

Merged
viktorstrate merged 1 commit intoviktorstrate:mainfrom
beezly:fix/timeline-memory-leak
Apr 9, 2026
Merged

Fix memory leak: use weak self in timeline observation loop#96
viktorstrate merged 1 commit intoviktorstrate:mainfrom
beezly:fix/timeline-memory-leak

Conversation

@beezly
Copy link
Copy Markdown
Contributor

@beezly beezly commented Apr 8, 2026

Summary

  • TimelineViewController.listenForFocusTimelineItem() uses withObservationTracking with a recursive onChange closure to watch for focused event changes. The closure captured self strongly, meaning the observation system held the TimelineViewController alive indefinitely — even after switching rooms. Since TimelineViewController holds LiveTimeline which holds LiveRoom, the entire timeline object graph accumulated with each room switch.
  • Fix: capture [weak self] in the onChange closure so the observation chain breaks when the view controller is deallocated.

Relates to #89

Verification with heap

You can verify the fix using the heap command-line tool. Get the PID of the running app with pgrep -x Mactrix or from Activity Monitor, then:

  1. Open the app, select a room, run heap <pid> | grep -E 'LiveTimeline|LiveRoom' — should show 1 of each
  2. Switch between ~20 rooms
  3. Run the same heap command again — without the fix the counts match the number of room switches; with the fix they stay at 1

@viktorstrate viktorstrate merged commit 48b3c80 into viktorstrate:main Apr 9, 2026
2 checks passed
@viktorstrate
Copy link
Copy Markdown
Owner

Neat with the heap command, I didn't know that one. Thank you, for finding this! Using the app now consistently uses 500-700 MB on my machine when navigating around different timelines with images etc.

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.

2 participants