-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
  • 57,132
  • 21
  • 101
  • 108
Selva
  • 841
  • 10
  • 24
  • 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,176
  • 8
  • 62
  • 86
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
  • 37,849
  • 27
  • 129
  • 182
  • 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