Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to mannually free the servletContext variable to free memory?

 
wei liu
Ranch Hand
Posts: 35
Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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


 
ujjwal soni
Ranch Hand
Posts: 403
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try this..

 
wei liu
Ranch Hand
Posts: 35
Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
ujjwal soni
Ranch Hand
Posts: 403
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can call the garbage collector manually

 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 403
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, thanks for the info...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic