HELP OpenSubKey leaks Memory!

R

Rudy Meijer

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 ??????????
 
N

Nicholas Paldino [.NET/C# MVP]

Rudy,

This looks ok to me. What is giving you the impression that it is
leaking memory? Is it because you see your memory usage go up in Task
Manager? If so, then this is not an indication that you are leaking memory.
This is the normal behavior for .NET programs.

Hope this helps.
 

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