In the last few weeks I was debugging an application to find leaking memory. I found lots of tips in this MSDN article. Something I found few times is that people are not aware that you MUST call Dispose() after you call ShowDialog (see Microsoft docs).
The simplest way to create a memory leak with a form:
{
Form form = new FooForm();
form.Owner = this
form.ShowDialog();
}
After this code block will finish the form "form" will stay in the memory because the owner form holds a refrence to the form in OwnedForms. To free the memory you must call form.Dispose();
Sunday, July 1, 2007
Monday, May 28, 2007
Fast DataTable loading from IDataReader
I was using the Load method of DataTable to load data from IDataReader the other day, and while profiling the application I found out that this is my program bottleneck.
I've just wrote a quick & dirty function which does the same task much faster:
I've just wrote a quick & dirty function which does the same task much faster:
private static DataTable ReaderToDataTable(IDataReader reader)
{
int fieldCount = reader.FieldCount;
DataTable result = new DataTable("Query Result");
for (int i = 0; i < reader.FieldCount; i++)
{
DataColumn column = result.Columns.Add(reader.GetName(i));
column.DataType = reader.GetFieldType(i);
}
object[] row = new object[fieldCount];
while (reader.Read())
{
reader.GetValues(row);
result.Rows.Add(row);
}
return result;
}
Labels:
C#,
Performance
Friday, May 25, 2007
Friday, May 18, 2007
Creating a MOSS Demo/Test machine
I've being installing a testing virtual machine for MOSS 2007 related application. While searching the internet I've found this post which describe step by step how to install MOSS machine.
Labels:
MOSS
Memory Debugging in .NET applications
Long time ago I found a post regarding memory debugging in .NET applications:
Analyzing Common CLR Performance Problems
That post address lots of memory leak types, while usually I encouter memory leaks from the heap. Here's the summary how to find heap memory leaks:
1. Start the windows debugger: WinDbg (can be downloaded from here).
2. Attach to the target .NET process
3. Load the SOS module, in the WinDbg console write:
.loadby sos mscorwks
4. List all the allocated objects:
!dumpheap -stat
At this point you can break & resume the program as you wish.
Other Useful commands:
!finalizequeue - show the list of objects waiting for finalize thread
!threads - running threads
!eeheap -gc - show the object generations in the GC
Full (?) list of commands can be found here
Analyzing Common CLR Performance Problems
That post address lots of memory leak types, while usually I encouter memory leaks from the heap. Here's the summary how to find heap memory leaks:
1. Start the windows debugger: WinDbg (can be downloaded from here).
2. Attach to the target .NET process
3. Load the SOS module, in the WinDbg console write:
.loadby sos mscorwks
4. List all the allocated objects:
!dumpheap -stat
At this point you can break & resume the program as you wish.
Other Useful commands:
!finalizequeue - show the list of objects waiting for finalize thread
!threads - running threads
!eeheap -gc - show the object generations in the GC
Full (?) list of commands can be found here
Labels:
.NET Debugging
Subscribe to:
Posts (Atom)