What is the fastest way to release memory of stringbuilder .
StringBUilder sb = new StringBuilder();
sb.apppend(maximum value possible);
Below are the code snippets which i tried to release memory as fast as possible and make the object eligible for garbage collection
Option 1:
sb = null;
As per my understanding all the data in the stringbuilder will be deleted and object will be eligible for garbage collection as soon as it is kicked in, but the memory of the text which is occupied by stringbuilder will be released. Also will the string value in it also be deleted from heap or will be stored in string pool ?
Option 2:
sb.setLength(0);
This will reset the lenght of string builder but it will not be garbage collected
Option 3:
sb.delete(0,sb.length());
This will reset the string builder by deleting all the data in it but it will not be garbage collected
Option 4:
sb.delete(0,sb.length());
sb = null;
This will reset the string builder and also make it eligible for garbage collection?!