We have an application that is mixed .NET 2.0 and native C++. In our testing, we have a mode which can automatically loop through a set of projects. A project opens, runs, closes, repeat. Each of these steps requires creation/destruction of windows (winforms to be precise). Recently we've experienced some odd behavior in performance. After running for a few hours the opening and closing parts slow down (blocking the gui thread and showing half drawn screens etc). Now it would be easy to chock this up to a resource leak...but we're tracking handles and memory, and while memory grows slightly there's nothing to indicate this level of problem. Handles are stable. So maybe dangling event handlers...still need to investigate that. But the kicker, which perplexes me, is that shutting down the application and restarting it doesn't bring back the initial performance. It's still slow until I reboot the OS (win XP) and then performance starts out snappy again. This really perplexes me as I assume shutting down the application will reclaim all resources. Any thoughts?
+1
A:
Sounds like a possible GDI handle leak. GDI objects are not automatically picked up by the Garbage Collector.
.NET Memory Profiler (http://memprofiler.com/) does a good job of tracking these (there is a 14 day trial version).
Have you seen these:
Resource Leaks: Detecting, Locating, and Repairing Your Leaky GDI Code
Detect and Plug GDI Leaks in Your Code with Two Powerful Tools for Windows XP (has a link to a GDI Handle viewer tool).
Mitch Wheat
2009-10-28 15:15:25
I'll second the use of the Memory Profiler. It lets you take snapshots and compare them - so you can take a snapshot on one iteration, take another on the next one, and diff them - you can see exactly what is growing between common iterations of your app.
stusmith
2009-10-28 15:24:43
I have .NET Memory Profiler and will try that - but the fact that restarting the application (without reboot) doesn't fix the problem would not be explained by anything in process growth.
2009-10-28 16:17:40
That's not true for certain limited system resources such as GDI handles....
Mitch Wheat
2009-10-29 00:44:12
GDI handles are collected by the OS when the application shuts down. The original poster (don't know how to refer to him/her without the name) needs to verify that the application is indeed closed when they think it is closed. Maybe there are other processes in the system which the application works with (or services, or custom drivers), and maybe they stick around after the app is gone
Rom
2009-10-29 08:10:14
A:
You're assuming its a resource leak (which isn't a bad guess), but it might be something else.
Have you tried using a performance profiler?
Joseph
2009-10-28 15:27:07
A:
Guessing is a bad option. You need to use some profiler. Personally, I prefer YourKit .NET profiler http://www.yourkit.com/dotnet/
You'll immediately find slow code.
Serge
2009-10-29 13:04:54