pradeep wrote:

> Hi All
>
> Can anybody hint me on the following questions:
>
> 1.In the context of a servlet , how the memory will be allocated and freed ,
> when
>     1. a servlet is loaded and has some member variables.

The servlet instance itself, and the contents of its member variables, are
freed when the servlet engine calls the destroy() method of your servlet and
releases the instance.  For Apache JServ, that only happens when you shut it
down, or when you have auto-reloading enabled and you modify one of the servlet
classes.

Note that the member variable objects can only be freed if this servlet had the
only references to them.  If there are any other references to the same
objects, the objects won't be freed.

>
>     2.a response is sent for a request from browser and some variables
> declared in the
>       doGet/doPost   method.

These variables are local to the doGet() or doPost() method.  If there are no
other references to those objects, they can be freed -- but again, if you have
passed references to them to other objects, and they maintain those references,
then your objects are still in use.

>
>     3.session tracking made by storing some values for each user
> session(will the memory be
>        freed  when user closes his session).

Session variables are released when you call removeValue(), or when the session
is invalidated (either you call invalidate(), or the session times out).

At the risk of sounding like a broken record, you need to check here for shared
references as well.

>
> 2. Is there anyway in which I can destroy a servlet?Will recompiling the
> servlet executes Destroy method?
>

If you have auto-reloading enabled on Apache JServ, modifying a class file will
cause all the servlets and sessions currently loaded to be freed, and
everything restarted.  See below for a note about when the GC actually happens.



>
> I am facing the serious problems as the memory allotted for my
> servelts(around 15-20) is never getting released and when multiple requests
> comes , the situation is horrible.
>

How are you determining that it didn't get released?  There are a several
additional things to consider:

* Just because an object has been "freed" does not mean that the garbage
collector
  will go grab it immediately.  The value returned by the Runtime.freeMemory()
call
  will keep going down until the JVM actually does call the GC.

* What do you have the maximum heap size set to?  The JVM default is usually
  something like 16 megs or 32 megs, if you haven't set a value explicitly.
  The JVM is not required to call the garbage collector at all, if its current
  memory usage is less than the maximum.  It can just grab some more
  memory and use it, which is often faster than running the GC algorithm.

* Try calling Runtime.getRuntime().gc() yourself to force running the garbage
  collector, and see what happens.  It will collect any available released
objects
  immediately.

* If the GC does not collect much memory, then you (or software you are
  calling) has allocated references and not freed them.  The easiest way to
  consume tons of memory is do a bunch of JDBC calls and forget to close
  your result sets and statements -- but the principle applies to all the
  software you are using.  Only objects that are not referenced from
  *any* active object can be garbage collected.

* If you are looking at the memory allocated to your JVM by the operating
  system, this will never go down for the lifetime of the JVM.


>
> I am working on Apache Server 1.3.6/Apache JServ1.0/Webmacro Templates
> 0.83/Blackdown JDK117v3/JSDK2.0.
>

You'll also want to check the WebMacro documentation for any guidelines on
freeing objects that it requires.

>
> Please help me,
>
> regards,
> -pradeep
>

Craig McClanahan

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to