Skip to content

[Skia] A bitmap cache entry evicted by the LRU leaves its shared decoded surface to finalization #25128

Open

Description

@mikernet

Current behavior

With the bitmap cache enabled, a decoded BitmapImage surface that went through _bitmapImageCache is owned by the cache: the LRUCache entry holds the Task<ImageData>, and every BitmapImage that loaded the same key shares the result. When the LRU evicts that entry (capacity reached in Add, or Trim removing an idle entry on a memory-pressure interval), nothing owns the surface anymore. The sources still displaying it keep it alive through their ImageData, which is fine, but once they all unload nothing releases the decoded pixels deterministically: a cache-shared surface is never released by a source (one source cannot know whether another still displays it), so it goes to the finalizer chain, which is the path #25114 / #25124 removes for uncached surfaces.

The same applies to an in-flight cached load whose requesters all cancelled before it completed and whose entry was evicted meanwhile: the result is produced, marked shared, and dropped only by finalization.

Expected behavior

Cache entries that know their users, as WinUI's ImageCache does (it is released by its last BitmapImage, ImageProvider::RemoveImageCache / ImageCache::~ImageCache): a reference-counted entry whose surface is released when the entry has left the cache and its last requester has unsubscribed, and an evicted in-flight load with no remaining requesters releasing its eventual result.

Context

Follow-up to #25114 (deterministic release of uncached surfaces, PR #25124), raised during the review of #25124. The pre-existing behaviour for cached surfaces is unchanged by that PR.

Activity

  1. self-assigned this
    on Oct 8, 2026
  2. added
    7.1
    on Oct 14, 2026
  3. removed
    7.1
    on Oct 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions