There are several ways that developers can get caught out by unintentional resource leaks in .NET. I thought it would be useful to gather them in one place.
Please add yours with one answer per item, so the best get voted up :)
...
Hi All!
I use SetTimer API and I see a lot of code like this:
case WM_DESTROY:
// Destroy the timer.
KillTimer(hwnd, IDT_TIMER);
PostQuitMessage(0);
break;
Do I have to call KillTimer or the system will automatically free resources on the process exit? Does forgetting to call KillTimer lead to resource leaks?
I u...
I am wondering if it is possible to use WinDbg to kwown the callstack that lead to the allocation of a handle.
For example:
#include <windows.h>
#include <conio.h>
#include <iostream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
cout << "Press ENTER to leak handles." << endl;
_getch();
cout << "Leaking ha...
Hey Folks,
I have a doubt. I initialize COM, do CoCreateInstance and use some interfaces.Can I call CoUninitialize without calling Release? Does it cause any memory/resource leak?
Thanks in Advance,
-Mani.
...
I'm working on a .NET application that loads web pages using multiple WebBrowser controls. There are several threads and WebBrowser controls involved (this is a server application), each thread creating a WebBrowser control and running a message loop for it.
My question/issue is related to the WebBrowser control. Every time a web page i...
Naively, I expected a ThreadLocal to be some kind of WeakHashMap of Thread to the value type. So I was a little puzzled when I learned that the values of a ThreadLocal is actually saved in a map in the Thread. Why was it done that way? I would expect that the resource leaks associated with ThreadLocal would not be there if the values are...
Question:
Is there an easy way to get a list of types of resources that leak in a running application? IOW by connecting to an application ?
I know memproof can do it, but it slows down so much that the application won't even last a minute. Most taskmanager likes can show the number, but not the type.
It is not a problem that the ch...
I've been reading up on .NET Threading and was working on some code that uses a ManualResetEvent. I have found lots of code samples on the internet. However, when reading the documentation for WaitHandle, I saw the following:
WaitHandle implements the Dispose
pattern. See Implementing Finalize and
Dispose to Clean Up Unmanaged
...
Hi, I am using ADO.NET (.NET 1.1) in a legacy app. I know that DataAdapter.Fill() opens and closes connections if the connection hasn't been opened manually before it's given to the DataAdapter.
My question: Does it also close the connection if the .Fill() causes an Exception? (due to SQL Server cannot be reached, or whatever). Does it ...
I'm trying to debug a memory leak in a printer driver. I'm pretty sure it's a resource leak, not just a plain memory leak because analyzing heap with !heap -s in windbg doesn't show any increase. How do I monitor other kinds of objects with windbg? Number of GDI objects and open handles is not growing either, so what could it be?
The...
I'm creating a dashboard application that shows hundreds of "items" on a FlowLayoutPanel.
Each "item" is a UserControl that is made up of 12 or labels.
My app queries a database and then creates an "item" instance for each record, populating ethe labels and textboxes with data before adding it to the FlowLayoutPanel.
After adding abou...
I have a Windows server application, implemented in C++ using the Win32 API, that does a lot of serial and TCP/IP communication. As it runs, CPU usage gradually increases, until it reaches 100%. Task Manager indicates that most (>75%) of the CPU usage is by the "System" process. If I kill my server process, then CPU usage returns to n...