Sanjay,
A session is for ONE user across all jsp and
servlet of that particular web application. In other words, when we put session.setAttribute("loginId","Sanjay"), this "Sanjay" object is available for this paricular user in other jsps,servlets etc. Not for others!
Having said that, when we first time make a 'session.setValue(**,**), the fresh obj is loaded into heap memory of the server machine and an entry is put in a user specific session management HASH TABLE.
So when you make a for loop like this
case 1:
------
//What happens is there is ONLY ONE COPY of actual object referenced by myRef loaded into memory. You are trying to put the same object with SAME KEY 100 times. So HASHTABLE will each time find an already existing entry in it and will not add/replace the entry, finally only one entry to the user specific session management HASH TABLE
case 2:
-------
Here again only one copy of object referenced by myRef exixits in heap, BUT there are 100 entries in session management table , (which are just key,value pairs, NOT actual objs). This will not take much added memory, because this code adds extra key ,value pairs only in hashtable. Will not load a fresh session object into memory!
case 3:
-------
//Here 100 new fresh objects created and loaded into memory and there are 100 new key,value entries in master session management HASH TABLE. This is VERY BAD! Lots of wasted memory.
case 4:
-------
//same as case 3. 3 new session objects, occupying their own heap memory and 3 entries in HASHTABLE.
To visiualize what said, please see the diagram under 'session management' in this following jsp tutorial link.
http://developer.java.sun.com/developer/onlineTraining/JSPIntro/contents.html regds
maha anna
[This message has been edited by maha anna (edited March 31, 2001).]