This week's book giveaway is in the Programmer Certification forum.
We're giving away four copies of OCP Oracle Certified Professional Java SE 21 Developer Study Guide: Exam 1Z0-830 and have Jeanne Boyarsky & Scott Selikoff on-line!
See this thread for details.
  • 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
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

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: 7001
6
Eclipse IDE Python C++ Debian Java Linux
  • 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
 
You guys wanna see my fabulous new place? Or do you wanna look at this tiny ad?
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic