Memory/Leak Tool?

C

Chris Botha

I have a Windows app (it will be promoted to a Service once this problem is
sorted out) that cyclically, every minute, connects to five SQL Servers over
the WAN, extract data and insert the data in a local SQL Server, using the
OLEDB provider. Every cycle I create one local connection and five remote
connections, do the stuff, close the connections and dispose everything that
has a Dispose method (OleDbConnection, OleDbDataAdapter and OleDbCommand).
After running overnight the performance degrades and if I examine the
Private Bytes of the process (using Performance Monitor, the way we looked
for memory leaks before DOTNET in C++, but should still be valid), it goes
up from approx. 1.3 MB to over 2 MB.
I've been using DOTNET from the first Beta and never thought I'd say this,
but I suspect a leak.
Is there a method/tool that will show me the type of DOTNET objects being
leaked, or give me some indication of where to look for the problem?

Thanks.
 
Y

Yechezkal Gutfreund

Are there also tools for these items for the COMPACT Framework?

0. Memory usage and leaks
1. CPU usage (by thread, etc.)
2. Monitor thread states
3. Other system profiling tools
 
L

Lloyd Dupont

in the compact framewrok there is hardly memory leak.
but be carefull with:
- listener (anObject.anEvent += a pointer to method of an object which won't
be disposed !)
- static variable (which won't be disposed either !)

regarding tools I don't much .. sorry ...
 
A

Andrew Martin

Chris Botha said:
I have a Windows app (it will be promoted to a Service once this problem is
sorted out) that cyclically, every minute, connects to five SQL Servers over
the WAN, extract data and insert the data in a local SQL Server, using the
OLEDB provider. Every cycle I create one local connection and five remote
connections, do the stuff, close the connections and dispose everything that
has a Dispose method (OleDbConnection, OleDbDataAdapter and OleDbCommand).
After running overnight the performance degrades and if I examine the
Private Bytes of the process (using Performance Monitor, the way we looked
for memory leaks before DOTNET in C++, but should still be valid), it goes
up from approx. 1.3 MB to over 2 MB.
I've been using DOTNET from the first Beta and never thought I'd say this,
but I suspect a leak.
Is there a method/tool that will show me the type of DOTNET objects being
leaked, or give me some indication of where to look for the problem?

Thanks.

This is how we do it. We had code that called a dll written in native
code. We were able to map out the memory leak pretty quickly.

-a


using System;
using System.Runtime.InteropServices;
using System.IO;

namespace MemoryCheck
{
public class Memory
{
public Memory()
{
}

private struct MEMORYSTATUS
{
public Int32 dwLength;
public Int32 dwMemoryLoad;
public Int32 dwTotalPhys;
public Int32 dwAvailPhys;
public Int32 dwTotalPageFile;
public Int32 dwAvailPageFile;
public Int32 dwTotalVirtual;
public Int32 dwAvailVirtual;
}

[DllImportAttribute("coredll.dll")]
private static extern void GlobalMemoryStatus(ref MEMORYSTATUS lp);

private static string getMemInfo()
{
MEMORYSTATUS ms=new MEMORYSTATUS();
GlobalMemoryStatus(ref ms);
return "\r\n" + DateTime.Now.ToString() +
"," + "dwMemoryLoad:" +
"," + ms.dwMemoryLoad +
"," + "dwTotalPhys:" +
"," + ms.dwTotalPhys+
"," + "dwAvailPhys:" +
"," + ms.dwAvailPhys +
"," + "dwTotalVirtual:" +
"," + ms.dwTotalVirtual +
"," + "dwAvailVirtual:" +
"," + ms.dwAvailVirtual + "\r\n";
}

public static void WriteMemory()
{
System.IO.StreamWriter sr = new StreamWriter(@"\test.txt", true);
sr.WriteLine(getMemInfo());
sr.Close();

return;
}
}
}
 
A

Andrew Martin

Lloyd Dupont said:
in the compact framewrok there is hardly memory leak.
but be carefull with:
- listener (anObject.anEvent += a pointer to method of an object which won't
be disposed !)
- static variable (which won't be disposed either !)

regarding tools I don't much .. sorry ...


using System;
using System.Runtime.InteropServices;
using System.IO;

namespace MemoryCheck
{
public class Memory
{
public Memory()
{
}

private struct MEMORYSTATUS
{
public Int32 dwLength;
public Int32 dwMemoryLoad;
public Int32 dwTotalPhys;
public Int32 dwAvailPhys;
public Int32 dwTotalPageFile;
public Int32 dwAvailPageFile;
public Int32 dwTotalVirtual;
public Int32 dwAvailVirtual;
}

[DllImportAttribute("coredll.dll")]
private static extern void GlobalMemoryStatus(ref MEMORYSTATUS lp);

private static string getMemInfo()
{
MEMORYSTATUS ms=new MEMORYSTATUS();
GlobalMemoryStatus(ref ms);
return "\r\n" + DateTime.Now.ToString() +
"," + "dwMemoryLoad:" +
"," + ms.dwMemoryLoad +
"," + "dwTotalPhys:" +
"," + ms.dwTotalPhys+
"," + "dwAvailPhys:" +
"," + ms.dwAvailPhys +
"," + "dwTotalVirtual:" +
"," + ms.dwTotalVirtual +
"," + "dwAvailVirtual:" +
"," + ms.dwAvailVirtual + "\r\n";
}

public static void WriteMemory()
{
System.IO.StreamWriter sr = new StreamWriter(@"\test.txt", true);
sr.WriteLine(getMemInfo());
sr.Close();

return;
}
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top