I have a method in a class where I create a string like this:
private void log(HttpServletRequest request, HttpServletResponse response) {
String result = "Following request " + request.getRequestURI() + " yielded " + response.getStatus();
log.info(result);
}
My question is, result
string is generated millions of times. Does it have impact on heap memory?
My current understanding is that each method has its own heap memory allocation. After method finishes executing, all local variables vanish from memory.
My other understanding is that Strings are stored in global heap memory, and they get cleaned up on next Garbage collection cycle.
Can someone please put some light on this I shall be thankful.