473,804 Members | 3,804 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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\Micr osoft\Windows\C urrentVersion\R un";
public runKey()
{
// Fetch the hklm run key values.
rk = Registry.LocalM achine.OpenSubK ey(subKey);
m_names = rk.GetValueName s();
}

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(obj ect sender, System.EventArg s e)
{
using (runKey rk = new runKey())
{
if ( rk.Names.Length > nrofRunEntries )
{
....;
}
}
}

Why is it leaking memory ??????????

Nov 17 '05 #1
1 2447
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.co m

"Rudy Meijer" <Ru*********@gm ail.com> wrote in message
news:11******** *************@g 44g2000cwa.goog legroups.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\Micr osoft\Windows\C urrentVersion\R un";
public runKey()
{
// Fetch the hklm run key values.
rk = Registry.LocalM achine.OpenSubK ey(subKey);
m_names = rk.GetValueName s();
}

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(obj ect sender, System.EventArg s 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
2017
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 memory in terms of the length of the list i? If so why not and how could I change it to be so? I am sure the solution is O(n) since the list must only iterated once and the dictionary is O(1), correct? Thanks for the help!! #You are given a...
4
6772
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 = Linux galahad 2.4.19-64GB-SMP #1 SMP /etc/sysctl.conf kernel.shmmax=268435456
5
1395
by: LinuxGuy | last post by:
Can someone please tell if following code leaks memory void someFunction() { char MyArray; memset(MyArray,0,512); }
4
1671
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 properly during destruction. For now, I need a portable function that can tell me the available free store memory. With that, I can do things like: size_t mem = getFreeStoreAvailable(); {
2
1383
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 collection process in stack memory -Reuse and access address in stack memory I'm a newbie >>> Thanks very much...
0
1213
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 level memory leak with Application level Memory leak? Thanks in Advance,
2
2014
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 chart once per second while using control panel to observe memory loss. I have a little button to turn off the redraw as a sanity check to verify that memory isn't leaking all by itself. I have tried plotkit. I have tried drawing on a canvas...
2
1383
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 , and i cant unhide it or find it . i can autohide memory 2 ,3 and 4 and find them all the time , so its JUST memory 1 that has disappeared .. oh and on the note of memory windows , . Seems to me that I could use a statement like this one. byte...
3
1797
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 consequences that are a little unclear in the documentation. If I create a shared memory block of x bytes. 1) How do I check the total that are being *used*. With
0
9576
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10310
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10074
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9138
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7613
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6847
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4291
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3809
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2983
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.