Hello,
I made a class which read a key from the registry. This class is called
every second in a timer event.
Everything works fine but the class leaks memory. about 4Kb/s
taskmanager.
public class runKey: IDisposable
{
RegistryKey rk;
string[] m_names;
static string subKey =
@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run ";
public runKey()
{
// Fetch the hklm run key values.
rk = Registry.LocalMachine.OpenSubKey(subKey);
m_names = rk.GetValueNames();
}
public void Dispose()
{
rk.Close();
rk = null;
m_names = null;
}
public string[] Names
{
get {return m_names;}
}
}
And here is the timer event code that called the class above:
private void timer1_Tick(object sender, System.EventArgs e)
{
using (runKey rk = new runKey())
{
if ( rk.Names.Length > nrofRunEntries )
{
....;
}
}
}
Why is it leaking memory ??????????