What is GC in Java Interview Questions? Why is there GC?

What is GC? Why is there GC?

Answer: GC means garbage collection. Memory processing is a place where programmers are prone to problems. Forgetting or wrong memory recycling can cause instability or even crash of the program or system. The GC function provided by Java can automatically detect whether the object exceeds the scope. So as to achieve the purpose of automatic memory recovery.

Java does not provide a display operation method to release allocated memory. Java programmers don't need to worry about memory management, because the garbage collector will manage it automatically. To request garbage collection, you can call one of the following methods: System.gc() or Runtime.getRuntime().gc(), but the JVM can block the displayed garbage collection calls.

Garbage collection can effectively prevent memory leaks and effectively use available memory. The garbage collector is usually performed as a separate low-priority thread. Under unpredictable circumstances, objects that have died or have not been used for a long time in the memory heap are cleaned and recovered. The programmer cannot call the collector in real time. Garbage collection of an object or all objects.

In the early days of Java, garbage collection was one of the biggest highlights of Java, because server-side programming needed to effectively prevent memory leaks. However, time has passed, and Java's garbage collection mechanism has now become a criticized thing. Mobile smart users usually feel that the IOS system has a better user experience than the Android system. One of the reasons is the unpredictability of garbage collection in the Android system.

Guess you like

Origin blog.csdn.net/weixin_44296929/article/details/108344307