The garbage collection thread runs with low priority. Therefore, this thread does not perform its task to perform the cleanup task.
It is also not guaranteed that the garbage collection stream will always work. Here in your application, a low priority garbage collection thread does not get the ability to execute on application threads. Thus, the heap is not cleared of unused objects, and therefore, the application slows down due to the limited heap size.
You can count the amount of garbage collected by overriding the public void finalize() method. Learn more about javadoc
I would recommend that you use some java profilers to diagnose a memory problem.
source share