This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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 Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "freeing up of memory used by strings" Watch "freeing up of memory used by strings" New topic
Author

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
Rancher

Joined: Mar 22, 2000
Posts: 12761
    
    5
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.
Bill

------------------
author of:
 
Don't get me started about those stupid light bulbs.
 
subject: freeing up of memory used by strings
 
Similar Threads
Difference between s = "" and new String("a")
String
String's intern method
Out of Memory Error - optimisation tips?
Strings