473,385 Members | 2,028 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,385 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 5016
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
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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...
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.