Home > Back-end >  The Java hashmap=null, gc will automatically recycling all the inside of the heap memory space
The Java hashmap=null, gc will automatically recycling all the inside of the heap memory space

Time:05-15

A collection of other class object also have same problem, the clear automatically after recycling

CodePudding user response:

Hashmap between the key and the value of a strong reference, will not be garbage collected
If it is a new map inside elements, is the need to manually release
The map. The clear () just returned the memory to the heap, did not return to the OS, there is a memory object, process memory will always increase
The map=null his hand release

CodePudding user response:

Garbage collection in Java will according to the usage and priority gc will automatically recycling
C + + is to manually release the new things

CodePudding user response:

Hashmap=null just put the map object is empty, the element inside still exist, but lost contact the references, GC is recycling, then the JVM determined according to the situation, not necessarily immediately recycling

CodePudding user response:

Hashmap itself must I don't care, care about containing objects, those objects in the heap memory will automatically be gc collection
  • Related