473,326 Members | 2,081 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,326 software developers and data experts.

Hashtable, memory leak?

I'm seeing what looks like a leak with Hashtable, but guessing it is
something I'm doing -

void func1()
{
Hashtable hash = getHash();

//Loop thru assorted data, check to see if data exists as key in
hashtable.

hash.Clear();
hash = null;
}

Hashtable getHash()
{
//populate and return new hashtable...
}

The memory consumption (found with GC.GetTotalMemory(false) ) keeps on
rising after each call to func1(), even though I've cleared the hash. Is
there something else I need to do? If I don't create and check the hash
keyset, memory consumption stays very low.

And, I am using the hash simply as a fast reference comparison,
if(hash.containskey("key I'm looking for")) kindof logic, all I really want
is the keyset but couldn't find a way to do that. The hash will sometimes
be loaded with *lots* of keys. I tried arraylist and the contains method,
but that was way to slow.

Thanks in advance!

Derrick
Nov 16 '05 #1
1 4997
Memory would grow, as every time you are allocating and populating a new
hashtable object. If you do this repeatedly, then memory will keep growing.

When memory gets high enough, the GC should kick in, and clean up all those
hashtables that are no longer being referenced by anything.

Also, you don't need to set the hashtable variable to 'null'.

"Derrick" <de*********@excite.com> wrote in message
news:uk*************@TK2MSFTNGP12.phx.gbl...
I'm seeing what looks like a leak with Hashtable, but guessing it is
something I'm doing -

void func1()
{
Hashtable hash = getHash();

//Loop thru assorted data, check to see if data exists as key in
hashtable.

hash.Clear();
hash = null;
}

Hashtable getHash()
{
//populate and return new hashtable...
}

The memory consumption (found with GC.GetTotalMemory(false) ) keeps on
rising after each call to func1(), even though I've cleared the hash. Is
there something else I need to do? If I don't create and check the hash
keyset, memory consumption stays very low.

And, I am using the hash simply as a fast reference comparison,
if(hash.containskey("key I'm looking for")) kindof logic, all I really want is the keyset but couldn't find a way to do that. The hash will sometimes
be loaded with *lots* of keys. I tried arraylist and the contains method,
but that was way to slow.

Thanks in advance!

Derrick

Nov 16 '05 #2

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

Similar topics

8
by: ranjeet.gupta | last post by:
Dear All Is the Root Cause of the Memory corruption is the Memory leak, ?? suppose If in the code there is Memory leak, Do this may lead to the Memory Corruption while executing the program ? ...
17
by: José Joye | last post by:
Hi, I have implemented a Service that is responsible for getting messages from a MS MQ located on a remote machine. I'm getting memory leak from time to time (???). In some situation, it is...
1
by: Derrick | last post by:
I'm seeing what looks like a leak with Hashtable, but guessing it is something I'm doing - void func1() { Hashtable hash = getHash(); //Loop thru assorted data, check to see if data exists...
33
by: Ken | last post by:
I have a C# Program where multiple threads will operate on a same Hashtable. This Hashtable is synchronized by using Hashtable.Synchronized(myHashtable) method, so no further Lock statements are...
4
by: Don Nell | last post by:
Hello Why is there a memory leak when this code is executed. for(;;) { ManagementScope scope = new ManagementScope(); scope.Options.Username="username"; scope.Options.Password="password";...
23
by: James | last post by:
The following code will create memory leaks!!! using System; using System.Diagnostics; using System.Data; using System.Data.SqlClient; namespace MemoryLeak
8
by: Adrian | last post by:
Hi I have a JS program that runs localy (under IE6 only) on a PC but it has a memory leak (probably the known MS one!) What applications are there that I could use to look at the memory usage of...
7
by: Salvador | last post by:
Hi, I am using WMI to gather information about different computers (using win2K and win 2K3), checking common classes and also WMI load balance. My application runs every 1 minute and reports...
3
by: Jim Land | last post by:
Jack Slocum claims here http://www.jackslocum.com/yui/2006/10/02/3-easy-steps-to-avoid-javascript- memory-leaks/ that "almost every site you visit that uses JavaScript is leaking memory". ...
22
by: Peter | last post by:
I am using VS2008. I have a Windows Service application which creates Crystal Reports. This is a multi theaded application which can run several reports at one time. My problem - there is a...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.