How does garbage collection work with session objects in Java?
How does garbage collection work with session objects in JSPS? Will each session collect garbage after the session expires? What is a better way to handle memory using the session object in JSP?
Solution
The garbage collector will only collect objects that do not have any hard references in the code The internal code of servletcontainer refers to the httpsession object When the session expires, the servletcontainer's internal code will dereference it, and GC will scan it at its time
You don't have to worry about that at all It's done for you
If your actual problem is excessive memory usage and / or insufficient memory, the cause of the problem must be elsewhere and must be solved in different ways Basically, you should not reference more than necessary objects