This week's book giveaway is in the Spring forum.
We're giving away four copies of Spring Boot in Practice and have Somnath Musib on-line!
See this thread for details.
Win a copy of Spring Boot in Practice this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

Hashtable and Vector problems...

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try calling System.gc() after the clear, which "suggests" that the Java virtual machine run the garbage collector.
 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 6968
2
Eclipse IDE Debian Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ?
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
reply
    Bookmark Topic Watch Topic
  • New Topic