Skip to content

[Skia] BitmapCreateOptions.IgnoreImageCache still adds the load to the static bitmap cache #25098

Closed

Description

@mikernet

Current behavior

On Skia heads, a BitmapImage with CreateOptions="IgnoreImageCache" skips the lookup in the static _bitmapImageCache, but its load task is still added to that cache. The decoded image is therefore retained by the cache for as long as it takes 100 newer images to evict it, exactly as if the option were not set.

Decompiled from Uno.WinUI 6.8.0-dev.212 (uno-runtime/net10.0/skia/Uno.UI.dll, BitmapImage.TryOpenSourceAsync):

bool ignoreCache = CreateOptions.HasFlag(BitmapCreateOptions.IgnoreImageCache);
var cacheKey = new BitmapImageCacheKey(uri, decodeWidth, decodeHeight);

if (ignoreCache || !_bitmapImageCache.TryGetValue(cacheKey, out var task))
{
    task = Task.Run(...);

    if (FeatureConfiguration.Image.EnableBitmapImageCache)   // <- not gated on ignoreCache
    {
        _bitmapImageCache.Add(cacheKey, task);
        ct.Register(() => _bitmapImageCache.Remove(cacheKey));
    }
}

The same shape is in src/Uno.UI/UI/Xaml/Media/Imaging/BitmapImage.cs on master.

Why it matters

The cache is bounded by entry count (FeatureConfiguration.Image.MaxBitmapImageCacheCount, default 100), not by bytes. A full-size image decodes to width × height × 4 bytes; on WebAssembly the browser-decoded pixel array is additionally wrapped with SKImage.FromPixels and pinned (ImageSourceHelpers.ReadFromStreamAsCompositionSurface), so each cached 4000×2667 image holds ~40 MB of pinned managed memory. A document viewer that shows a few dozen such images pins over a gigabyte that no element owns, and on WebAssembly that reaches the 2 GB linear memory limit and terminates the runtime. IgnoreImageCache is the documented way to keep such images out of the cache, and it has no effect.

Expected behavior

IgnoreImageCache should neither read from nor write to the cache, so the decoded image lives only as long as the BitmapImage that produced it.

Workaround

FeatureConfiguration.Image.EnableBitmapImageCache = false (global).

Environment

  • Uno.WinUI 6.8.0-dev.212, Uno.Sdk 6.8.0-dev.60
  • .NET 10.0.401, runtime pack 10.0.12
  • Heads: net10.0-browserwasm (Skia renderer) and net10.0-desktop

Activity

  1. added a commit that references this issue on Oct 8, 2026
    7c1c364
  2. added a commit that references this issue on Nov 2, 2026
    18fd11a
  3. added a commit that references this issue on Nov 3, 2026
    f6d489c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    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