This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

freeing up of memory used by strings  RSS feed

 
Sarada Bhasker
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!