Life of an object


General J2EE: Life of an object

  1. Life of an object (1 messages)

    If I create an object in init() method of a servlet. What will be its life duration ? Will it be there till servlet is loaded in memory of Application Server or will it be out of scope as soon as init() method execution ends ?


    Threaded Messages (1)

  2. Life of an object[ Go to top ]

    That depends on the reference to the object. If you put it in the ServletContext (or some other long living object) then it will live for long time. If the only reference to it is from a local variable in the init(), then it will be out of scope as soon as the init() finishes (like any local variable).