C
C#2y ago
HimmDawg

❔ Sudden OutOfMemoryException due to OS change?

Let's imagine a WinForms .NET Framework 4.8 app is running on Win10 just fine, but under Win11 it suddenly causes OutOfMemoryExceptions due to exceeding the handle limit. Do you guys have a clue what could be the problem? fluffyFoxThink
15 Replies
qqdev
qqdev2y ago
No, would need a stack trace or similar
HimmDawg
HimmDawgOP2y ago
There are several stack traces with different causes
OutOfMemoryException
Nicht genügend Arbeitsspeicher.
in System.Drawing

bei System.Drawing.Graphics.FromHdcInternal(IntPtr hdc)
bei System.Drawing.Font.get_SizeInPoints()
OutOfMemoryException
Nicht genügend Arbeitsspeicher.
in System.Drawing

bei System.Drawing.Graphics.FromHdcInternal(IntPtr hdc)
bei System.Drawing.Font.get_SizeInPoints()
for example
qqdev
qqdev2y ago
Is the memory usage actually exploding?
HimmDawg
HimmDawgOP2y ago
Gradually, but it crashes only under win11
qqdev
qqdev2y ago
Yeah, we have to figure out if the app is the issue or win11 Because it is often times the app itself Are you loading fonts/images or similar?
HimmDawg
HimmDawgOP2y ago
Some custom listviews were made by people before me and those are loading a metric ton of icons. Other than that, images are rare and we only use default fonts
qqdev
qqdev2y ago
You could check the code or use a memory profiler to check if there is unreleased memory hiding somewhere Is the app actually using the whole memory of the system btw? (before it crashes)
HimmDawg
HimmDawgOP2y ago
I thought as much. It was just odd that only Win11 causes that problem fluffyFoxThink it doesnt
qqdev
qqdev2y ago
Interesting Might be that the app always had this issue but only win11 is revealing it. Hard to tell Is the app using a lot of memory? In general
HimmDawg
HimmDawgOP2y ago
Not really. roughly 70 MB at most. And that's a pretty high estimation I am pretty sure the app always had a problem with GC and uncollected handles
qqdev
qqdev2y ago
You mentioned that the app is loading many icons Check if memory handling is fine there static code analysis might help too Idk if you use Rider or similiar
HimmDawg
HimmDawgOP2y ago
I'll do that foxNosy thanks
qqdev
qqdev2y ago
You are welcome! meowheart
Cracker
Cracker2y ago
You can try to take memory dump to analyze if there is a memory leak on some operation, It was easy to take from web servers but I am not sure how to do that for desktop app, probably easier but should search
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.

Did you find this page helpful?