What is the garbage collector in Java?

前端 未结 16 1184
故里飘歌
故里飘歌 2020-11-22 11:24

I am new to Java and confused about the garbage collector in Java. What does it actually do and when does it comes into action. Please describe some of the properties of the

16条回答
  •  一生所求
    2020-11-22 11:58

    To put it in the most simple terms that even a non-programmer can understand, when a program processes data it creates intermediate data and storage space (variables, arrays, certain object metadata etc.) for that data.

    When these objects are accessed across functions or over a certain size, they are allocated from a central heap. Then when they are no long needed, they need to be cleaned up.

    There are some very good articles online about how this works, so I'll just cover the very basic definition.

    The GC is basically the function that does this cleanup. To do this is clears table entries that aren't referenced by any active objects, effectively deleting the objects, than copies and compacts the memory. It's a little more complicated than this, but you get the idea.

    The big problem is some parts this process often requires the entire Java VM to require to be stopped temporarily to take place, as well as this entire process being very processor and memory bandwidth intensive. The various options as of GCs and tuning options for each one are designed to balance these various issues with the whole GC process.

提交回复
热议问题