dotnet/wpf · critical · OutOfMemoryException
E_OUTOFMEMORY
E_OUTOFMEMORY
Error message
OutOfMemoryException
What it means
MediaContext.NotifyPartitionIsZombie maps the render-thread failure HRESULT to a managed exception. When the failure code is E_OUTOFMEMORY it throws a bare OutOfMemoryException, indicating the render/UCE partition went zombie because the renderer ran out of memory.
Solutions
- Free visual resources: unload large images (set Source=null), call GC.Collect after releases, and reduce simultaneous large bitmaps.
- Switch to a 64-bit process to remove the 2GB address-space limit.
- Use DecodePixelWidth/Height to downscale images at decode time instead of full-resolution bitmaps.
- Profile memory (dotMemory/PerfMon) for leaks around Visuals, Images and bitmaps; check for the real OutOfMemoryException inner cause.
Example fix
// before
img.Source = new BitmapImage(new Uri("huge.jpg")); // full-res decode
// after
var bmp = new BitmapImage();
bmp.DecodePixelWidth = 800; // decode scaled-down
bmp.BeginInit();
bmp.UriSource = new Uri("huge.jpg");
bmp.EndInit();
img.Source = bmp; Defensive patterns
Strategy: try-catch
Validate before calling
// Pre-check process memory before loading large imagery: using var p = Process.GetCurrentProcess(); if (p.PagedMemorySize64 > 1L * 1024 * 1024 * 1024) FreeUnusedImages();
Try / catch
try { LoadLargeImages(); }
catch (OutOfMemoryException) { FreeUnusedImages(); GC.Collect(); GC.WaitForPendingFinalizers(); RetryWithDownscaling(); } Prevention
- Set DecodePixelWidth/DecodePixelHeight on all BitmapImages
- Run as 64-bit to lift the 2GB limit
- Release Image.Source for off-screen items (virtualization)
- Monitor private bytes and handle leaks in production
When it happens
Trigger: The render thread reports partition failure with HRESULT E_OUTOFMEMORY (via NotifySyncChannelMessage or NotifyChannelMessage) — usually after huge image allocations, excessive bitmap caching, or desktop heap / video-memory pressure.
Common situations: Loading many large images simultaneously, huge WriteableBitmap/RenderTargetBitmap allocations, memory leaks in visual-tree content, 32-bit process address-space exhaustion.
Related errors
- D3DERR_OUTOFVIDEOMEMORY
- WGXERR_UCE_RENDERTHREADFAILURE
- OutOfMemoryException
- SR.MediaContext_NoBadShaderHandler
- Win32Exception (native Win32 error from DuplicateHandle…
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/9c72312c8b235c75.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/MediaContext.cs:424
/// <summary>
/// The partition this media context is connected to went into
/// zombie state. This means either an unhandled batch processing,
/// rendering or presentation error and will require us to reconnect.
/// </summary>
private void NotifyPartitionIsZombie(int failureCode)
{
//
// We only get back these kinds of notification:-
// For all OOM cases, we get E_OUTOFMEMORY.
// For all OOVM cases, we get D3DERR_OUTOFVIDEOMEMORY and
// for all other errors we get WGXERR_UCE_RENDERTHREADFAILURE.
//
switch (failureCode)
{
case HRESULT.E_OUTOFMEMORY:
throw new System.OutOfMemoryException();
case HRESULT.D3DERR_OUTOFVIDEOMEMORY:
throw new System.OutOfMemoryException(SR.MediaContext_OutOfVideoMemory);
default:
throw new System.InvalidOperationException(SR.MediaContext_RenderThreadError);
}
}
/// <summary>
/// The back channel processed a malformed packet and so gives
/// the notification of invalid packet.
/// </summary>
private void HandleInvalidPacketNotification()
{
//
// -
// For now we ignore the packet and continue processing
// other packets. In future, we could also close this channel.
//View on GitHub (pinned to 81131a70a4)