We had a discussion just like this last week on a very similar
topic. The end result was that person didn't understand the JSP/servlet
lifecycle and was hanging onto memory that they expected they freed up but
didn't.
Here are some good to live by rules for Servlets/JSP:
1. Never use instance variables (i.e. variables declared outside of
a method as part of a class) - practically speaking they are never freed
2. Be careful with what you put into a session. Sessions generally
last 30 minutes past the last request, giving a big lag between memory being
needed and memory being available for others
Also, a few other notes that most people miss with Java:
1. If Java throws an OutOfMemoryException, there is no more memory
to collect. Java guarantees that before the exception is thrown the garbage
collector has run. If you get these exceptions then you still have
references to the memory.
2. Static variables hold their memory as long as the class is
loaded in memory (practically speaking, for the life of the application)
If you want to test if the memory is being consumed by the API,
create a simple application that calls the API a few times, checking the
available memory in between the calls (use the System class).
Randy
> -----Original Message-----
> From: Parmley, Scott C. [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, December 11, 2001 4:06 PM
> To: [EMAIL PROTECTED]
> Subject: Servlets and memory usage.
>
>
> Hello everyone.
>
> I've run into a big problem with memory usage in servlets,
> and I want to
> get some opinnions on this.
> Here is the scenerio:
>
> I am running tomcat 4.0.1 on both linux and windoze 2000.
>
> I am using Singleton-Labs' MonarchCharts API to render a nice
> PNG chart
> which is then served back to a JSP page making a URL request.
> Everything works fine, except if you look at memory
> utilization (on both
> platforms) it acts as though the image objects are never being cleaned
> up. Memory usage keeps growing and growing, until java
> exceeds its heap
> size.
>
> I am pretty festidious when implementing these chart objects
> and trying
> to clean up after myself, but to no avail. I also have not
> ruled out it
> could be the MonarchCharts APIs that are causing it. Has anyone run
> into a similar issue like this? Is there a way to schedule servlet
> memory to be garbage collected sooner?
>
> Hope this isn't too silly a question.
>
> Thanks in advance,
> -Scott
>
> --
> To unsubscribe: <mailto:[EMAIL PROTECTED]>
> For additional commands: <mailto:[EMAIL PROTECTED]>
> Troubles with the list: <mailto:[EMAIL PROTECTED]>
>
--
To unsubscribe: <mailto:[EMAIL PROTECTED]>
For additional commands: <mailto:[EMAIL PROTECTED]>
Troubles with the list: <mailto:[EMAIL PROTECTED]>