Memory allocated to string buffer is not getting cleared even we did
stringbuffer.delete(0,Stringbuffer.length());
stringbuffer = null;
System.gc();
Any suggestion to remove entire memory allocated to string buffer.
Memory allocated to string buffer is not getting cleared even we did
stringbuffer.delete(0,Stringbuffer.length());
stringbuffer = null;
System.gc();
Any suggestion to remove entire memory allocated to string buffer.
You cannot control Java memory management. Even by calling System.gc()
. By calling System.gc()
you can only suggest JVM to collect garbage but cannot force to free memory
Java will collect garbage memory based on its algorithm only
System.gc()
javadoc says
Calling the gc method suggests that the Java Virtual Machine expend effort toward recycling unused objects in order to make the memory they currently occupy available for quick reuse. When control returns from the method call, the Java Virtual Machine has made a best effort to reclaim space from all discarded objects.
Source :-System.gc()