This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes Servlets and the fly likes how to mannually free the servletContext variable to free memory? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "how to mannually free the servletContext variable to free memory?" Watch "how to mannually free the servletContext variable to free memory?" New topic
Author

how to mannually free the servletContext variable to free memory?

wei liu
Ranch Hand

Joined: Nov 19, 2008
Posts: 35

Hi,

I have designed a web application system that have mutiple domains, and in each domain I have a servletContext varaible to be used by all other servlet. and when I want to choose different domain, I need to free that servletContext variable to save memory. I have tried to kill the servletContext varaible by assigning null to itbut it does not seem to work.

I have -Xmx512m for my tomcat server


Many Thanks



SCJP 1.6 in 2010
SCWCD5 in 2011
ujjwal soni
Ranch Hand

Joined: Mar 28, 2007
Posts: 403
Try this..



Cheers!!!
Ujjwal B Soni <baroda, gujarat, india> <+919909981973>
"Helping hands are better than praying lips......"
wei liu
Ranch Hand

Joined: Nov 19, 2008
Posts: 35

ujjwal soni wrote:Try this..



thanks for your reply,

I have try this and it get slightly better, and I still get java heap error.

maybe need to allocate more memory to tomcat.

Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39547
    
  27
Make sure that whatever object is associated with "OWL" isn't referenced anywhere else, so that it is eligible for GC. The reference to it in the servlet context takes up hardly any memory at all by itself.


Ping & DNS - updated with new look and Ping home screen widget
ujjwal soni
Ranch Hand

Joined: Mar 28, 2007
Posts: 403
You can call the garbage collector manually

Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39547
    
  27
You can call the garbage collector manually

You shouldn't do that, though. Firstly, it's not "calling the GC", it's "asking the JVM to run a GC" which may well not happen (see the javadocs). And secondly, the JVM will run the GC on its own anyway if there's a need for it (low memory) - it's unnecessary to remind the JVM to do it.
ujjwal soni
Ranch Hand

Joined: Mar 28, 2007
Posts: 403
Ok, thanks for the info...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to mannually free the servletContext variable to free memory?
 
Similar Threads
Stack and Heap
garbage collection...
setting values in array
Variables trouble
difference between object and object reference.