File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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 Java Interview Guide 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: 13037
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:
I agree. Here's the link:
subject: freeing up of memory used by strings
It's not a secret anymore!