473,396 Members | 1,754 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

HELP OpenSubKey leaks Memory!

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

Nov 17 '05 #1
1 2418
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.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Rudy Meijer" <Ru*********@gmail.com> wrote in message
news:11*********************@g44g2000cwa.googlegro ups.com...
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 ??????????

Nov 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Jani Yusef | last post by:
I have a HW problem stated as shown at the top of the solution. The thing is is that I am not 100% sure wtf constant memory means. Well, I think I do but I am confused. Does my solution use contant...
4
by: PaulR | last post by:
Hi, We have a Server running SLES 8 and 3GB memory, with 1 DB2 instance and 2 active Databases. General info... DB2level = "DB2 v8.1.0.72", "s040914", "MI00086", and FixPak "7" uname -a =...
5
by: LinuxGuy | last post by:
Can someone please tell if following code leaks memory void someFunction() { char MyArray; memset(MyArray,0,512); }
4
by: Diego Martins | last post by:
Hi all! I am doing a crude investigation of memory leaks in objects created by external libraries. Since I don't have access to the source code, I can't tell if an object are freeing its resources...
2
by: nguyenlh | last post by:
I'm studying about Memory managerment - stack memory and I can't understand the following problems : Who can help me >> - Role of Stack memory -How to store address in stack memory -Garbage...
0
by: hairobinson | last post by:
Can any one help me explaing about Kernel Memory leak? what is kernel memory leak? how do we debug Kernel level Memory Leak? Do we have standard tool for finding it? How do we differentiate Kernel...
2
by: jhaxo | last post by:
How can I implement a cross browser javascript strip chart that does not leak memory. I have treid several off the shelf and home made charts. the basic test is to leave them running, redrawing the...
2
by: Jim Rutledge | last post by:
i am gettin back into programming with visual studio 2003 and using c# to program in . I am having trouble in debug mode when i click to use the Memory 1 window .. it has completely disappeared ,...
3
by: victor.s.email | last post by:
Hi, Im a Java developer new to PHP development. Im tasked to do some development playing with Shared Memory (shm http://forums.devshed.com/php-development-5/). Im a little curious about the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.