Fix memory leak: return early on image cache hit in MessageImageView#93
Merged
viktorstrate merged 1 commit intoviktorstrate:mainfrom Apr 9, 2026
Merged
Conversation
Owner
|
This is a nice fix generally, but it breaks drag and drop to download images. If you try to drag an image to the desktop it will not copy the file, because the For preview, it still works, since the |
The .task block checked NSCache on cache hit but never returned, causing getMediaContent to be called on every channel visit even for already-cached images. The fix always fetches raw data via the SDK (which hits its own disk cache on repeat loads, avoiding network requests), then skips the expensive decode step (toOrientedImage) when the NSImage is already in the NSCache. Two caching layers serve different purposes: - NSCache (checked in init): synchronously pre-populates `image` before the view appears, preventing flicker on scroll/revisit. The image is already on screen before .task runs its disk read. - SDK media cache (getMediaContent): avoids network re-fetches. Always called so `imageData` is populated for drag-and-drop, regardless of whether the decoded NSImage is cached. Fixes viktorstrate#89
2c666c1 to
8dfbbee
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes the memory leak where
getMediaContentwas called on every channel visit even for already-cached images.Two-layer caching design
NSCache (checked in
init): synchronously pre-populatesimagebefore the view appears, preventing flicker on scroll/revisit. Also skips the expensive decode step (toOrientedImage) on repeat loads.SDK media cache (
getMediaContent): avoids network re-fetches. Now always called in.tasksoimageDatais populated for drag-and-drop, regardless of whether the decodedNSImageis already cached.The image is already on screen (via
init) before.taskruns its disk read, so flicker prevention is unaffected.Re: drag-and-drop regression
The original version of this PR returned early on a cache hit without populating
imageData, breaking drag-and-drop. This revision always callsgetMediaContentto ensureimageDatais set, but still skips the decode step when theNSImageis already in the cache.Test plan
Fixes #89