dotnet / dotnet/wpf

WPF window and images take massive amount of memory compared to UWP

Open
#3,135 2 comments 7 reactions 0 assignees View on GitHub
Performance
Dominant language
C#
Stars
7.7k
Forks
1.3k
Avg merge
1d 11h
Merged PRs (30d)
61

Description

* .NET Core Version: 3.1.300
* Windows version: 19041.329, but also reproducible in earlier versions
* Does the bug reproduce also in WPF for .NET Framework 4.8?: Yes
* Is this bug related specifically to tooling in Visual Studio (e.g. XAML Designer, Code editing, etc...)? No



**Problem description:**

A WPF window and image seem to take a massive amount of memory compared to an equivalently sized window in UWP.

Possibly related issues:
- https://developercommunity.visualstudio.com/content/problem/724609/wpf-window-memory-usage-is-high-on-big-screens-on.html
- we are also seeing this error in some crash data, but haven't been able to reproduce in-house, so not clear if it is related https://github.com/dotnet/wpf/issues/128
System.OutOfMemoryException: Insufficient memory to continue the execution of the program.
at MS.Internal.HRESULT.Check(int hr)
at System.Windows.Media.Composition.DUCE+Channel.SyncFlush()
- I noticed encountering this issue as well, when resizing a WPF window, the Dedicated GPU usage column continually goes up in Task Manager. I guess it's a Task Manager bug but I'm wondering why it's manifested by WPF here.
https://support.microsoft.com/en-us/help/4490156/windows-10-1709-gpu-process-memory-counters-report-incorrect-values
Also see a lot of page faults.

**Minimal repro:**

Test apps for WPF and UWP

[WindowMemoryTestApps.zip](https://github.com/dotnet/wpf/files/4771955/WindowMemoryTestApps.zip)

1. Create a window
2. (optional) Add an image element at the size of the screen. It just increases the memory usage even further than a blank window alone
3. Resize the window to multiple monitors ( for example, 2 4Ks, or 1 4K monitor and other sized monitors)

Compare the memory usage in WPF vs. UWP

**Actual behavior:**
On my monitor setup with 7495 x 4440 virtual screen pixels, for WPF, sizing a window to that size takes around
![image](https://user-images.githubusercontent.com/5522385/84521894-b1272200-aca3-11ea-824a-f4e362600a82.png)

This is what a similar setup looks like in UWP.
![image](https://user-images.githubusercontent.com/5522385/84523071-b2f1e500-aca5-11ea-807b-339d01d4d2f8.png)

**Expected behavior:**
I would expect the behavior closer to UWP. I would expect say a (3840 x 2160 x 4 bytes per pixel) * 2 monitor setup to take 66,355,200 bytes, but WPF seems to be using many multiples of that.

Is this just an architectural limitation in WPF, or a bug?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.