views:

20

answers:

1

Consider,

pageContext.setAttribute("name", new String("Shal"));
String name1= new String("Jason");
pageContext.setAttribute("Alternate Name", name1));

how the memory is allocated for the above two attributes,how and when that memory allocated will be recovered. What is the best practice to follow

+1  A: 

Like all other java objects, they will be allocated on the heap, and garbage collected (a) when they are no longer reachable, and (b) when the garbage collector damn well feels like it.

Page-scoped attributes are no longer reachable when the page finishes executing, i.e. when the JSP has finished rendering, unless, of course, something else in the VM has another reference to them.

skaffman
I dont see how the `Shal` String is evicted. What am I missing ?
Guillaume
@Guillaume: Quite right, I misread the code
skaffman