-1

how the java memory works whenever a new class is instantiated, and when it gets garbage collected, etc.

And also there is difference in memory usage for the collection classes. For eg:Vector takes more memory than hash map like that.

Thanks in advance

Milen A. Radev
  • 60,241
  • 22
  • 105
  • 110
Selva
  • 839
  • 10
  • 25
  • 40

2 Answers2

3

Classes are not instantiated, rather classes are defined and objects from those classes are instantiated. when a object is instantiated using new operator memory is allocated.

Nipuna
  • 6,846
  • 9
  • 64
  • 87
1

When a new object is instantiated it takes up memory, when it is no longer used, it frees up memory. More items you put in a collection more memory it will take. When you no longer need an object you want to set to null.

fastcodejava
  • 39,895
  • 28
  • 133
  • 186
  • 1
    This probably isn't true anymore. See this question: http://stackoverflow.com/questions/850878/does-setting-java-objects-to-null-do-anything-anymore – Feanor Dec 10 '10 at 07:58