aspose file tools*
The moose likes Servlets and the fly likes freeing up of memory used by strings Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "freeing up of memory used by strings" Watch "freeing up of memory used by strings" New topic

freeing up of memory used by strings

Sarada Bhasker
Ranch Hand

Joined: Sep 11, 2000
Posts: 94
When is the memory used up by strings released in a servlet or JSP service method?
Will it make any difference if it is a string literal or string
created using new String() method;
William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 12835
Just like for every other object, Strings can be GCed when they have no reference. Your local variables can be GCed when the response is finished.
The trickiest chance for running low on memory would be if you store lots of objects in a session - they won't be GCed until the session is destroyed.
String literals are kept around and won't be freed as long as the Class is loaded.

author of:
It is sorta covered in the JavaRanch Style Guide.
subject: freeing up of memory used by strings