• Post Reply Bookmark Topic Watch Topic
  • New Topic

Hashtable and Vector problems...

 
senthil nathan
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have asked Vector and Hashtable in coding.When it was tested in server, admin people said that Vector and HashTable are taking more memory.So try to reduce it.My question is If i use HashTable.clear() and Vector.clear().I know that it will clear all elements from Vector and HashTable, does it releases the consumed space from memory also.
Thnks in Adv.
Senthil
 
Dan Cranmer
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try calling System.gc() after the clear, which "suggests" that the Java virtual machine run the garbage collector.
 
umar hathab
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Instead of Hashtable and Vector ,u can use HashMap and ArrayList respectively...When you use hashtable and vector ,it will take extra memeory as it would require some resource for synchronozation.If u dont really want synchronization in your code ,you can go for HashMap and ArrayList..
A.Umar
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think we need to know a little more about how you are using Hashtable and Vector. When correctly used, these objects themselves don't usually take up much space compared with the objects "inside" them.
Most memory problems I have encountered seem to be because too many objects are being created and then abandoned. The Garbage Collector just has trouble keeping up.
Both Hashtable and Vector allow a "guess at the size" parameter to the constructor, and both can slow down and gobble memory when they discard one set of data to move to a bigger one if you grow them a lot without pre-allocating a reasonable amount of space. Could this be the problem ?
 
Kevin McLain
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Memory isn't a big issue with Hashtable and Vector vs. HashMap and ArrayList however overall performance is. Since the former are synchronized unless you need them to be you are incurring a huge performance hit if they are accessed by multiple threads.
Kevin
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!