Our WPF 4.0 application have a cyclic high CPU usage (once every 3 minutes, up to 30%) which is indicated by windows taskmanager. At the time issue occurs there's nothing done with the UI (e.g we're not clicking anything, but we have for example label updated with time every second). There is something unpredictable about this high cpu jump: sometimes it takes place more frequently, sometimes less frequently (e.g every 30 seconds or every 9 minutes).
We use .NET 4.7.2 version (but this also takes place in .NET 4.6.2) and we compile all libraries and app itself to x86. We tested it on Windows 7 and Windows 10 operating systems (both reproducible).
Our application may consume up to 2.5 GB RAM (and most of the objects are long living objects, and they're in gen2) when all views are opened. But we also have this problem when just single panel is opened (and then we have 700MB of RAM consumption).
I did start the application and left it for 20 hours and perfmon has shown following results:
- We had 400 of Gen2 collections during that test.
- Bytes in All Heaps had not changed.
- Gen 2 heap size had not changed.
- LOH size had not changed.
- We didn't have induced GC.
- Whenever Allocated Bytes/s is updated, we can see 5~ Mbytes there.
- We had 3.1 GB ram used in total by all processes on a 8GB RAM machine.
- Promoted From Gen 1 increase to 3,860 every time just before gen2 collection takes place.
Here's the graph screen: Counter's Graph from PerfMon
- I did also checked what is the cause of GC triggering gen 2 with PerfView:
Condemned reasons from PerfView
Per generation GC Events from PerfView
- Here's a snapshot from WPF Analyzer:
- DotTrace's timeline has shown that .NET memory allocations comes mainly from WPF, System Code, String "subsystems". It also have shown that we have only UI thread running (except clr, and gc threads) and it calls MS.Win32.UnsafeNativeMethods.GetMessageW
This issue is much less common when we just switch WPF app to gcServerMode, but then it's just that Gen 2 collections takes place less frequently (every 2 hour then!).
We would like to avoid switching to server mode on UI app as this could impact user experience, and find the reason of gen2 collections...
Any suggestions what steps to take next to find the source of the problem? (gen 2 collections triggered by ...we don't know what!)