Hi,

      I have done analysis on static references and found a interesting
point al;so i find a difference in behaviour in tomcat 6 andtomcat 7

I created a class (TestStatic) which has a static reference to VO(java bean)
in my servlet i declared TestStatic as member variable and initialized it
there and i deployed my app and hit my servlet and then undeployed it ... i
used eclipse MAT and saw that both TestStatic and VO objects are not getting
garbage collected

then i changed the code in my servlet and removed TestStatic from member
variable i used spring beanfactory to get TestStatic object in my service
method and repeated step of deploying hitting my servlet and undeploying ..
i used eclipse MAT and saw that only VO object are not getting garbage
collected

so what can be concluded static references are never garbage collected ? or
even objects holding static references are not GC'ed.

In tomcat static refrence are getting garbage collected but in weblogic it
is not can any body help

below is code for reference
\





*package* com.leak;
 *public* *class* TestEnum {

        *private*   BeanName name;
        *private*  *static*  VO vo = *new* VO();

        *public* *void* printNames() {
                System.out.println(name.beanName);
        }}

 *package* com.leak;
 *import* org.springframework.beans.factory.BeanFactory;*import*
org.springframework.context.support.ClassPathXmlApplicationContext;

 *public* *class* UtilsN1 {
                
        *public*  *static*   BeanFactory factory=*null*;
        *public*  *static*  *void* setContext(BeanFactory factory ){
                UtilsN1.factory = factory;

                System.err.println( "Utils.factory>>" + factory );

        }

        *public*  *static* BeanFactory getFactory() {
                *return* factory;
        }}
 *package* com.leak;
 *import* java.io.IOException;*import* java.io.PrintWriter;
 *import* javax.security.auth.Destroyable;*import*
javax.servlet.ServletConfig;*import*
javax.servlet.ServletException;*import*
javax.servlet.http.HttpServlet;*import*
javax.servlet.http.HttpServletRequest;*import*
javax.servlet.http.HttpServletResponse;
 *import* org.springframework.beans.factory.BeanFactory;*import*
org.springframework.beans.factory.xml.XmlBeanFactory;*import*
org.springframework.core.io.ClassPathResource;*import*
org.springframework.core.io.Resource;
 *public* *class* Leak *extends* HttpServlet {
        *private* *static* *final* *long* serialVersionUID = 1L;
        TestEnum a = *new* TestEnum();

        @Override
        *public* *void* init(ServletConfig config) *throws* ServletException {
                super.init(config);

                Resource res = *new* 
ClassPathResource("applicationContext.xml");
                BeanFactory factory = *new* XmlBeanFactory(res);
                System.out.println("factory:::" + factory.getBean("test"));

                UtilsN1.setContext(factory);

        }

        *protected* *void* doGet(HttpServletRequest request,
                        HttpServletResponse response) *throws* 
ServletException, IOException {
                response.setContentType("text/html;charset=UTF-8");
                PrintWriter out = response.getWriter();
                out.println("<html><body><pre>");

                Test t = (Test) UtilsN1.getFactory().getBean(
                                BeanName.TEST.getBeanName());
                System.out.println(" test " + t);
                //TestEnum a = (TestEnum) 
UtilsN1.getFactory().getBean("testEnum");
                a.printNames();

                out.println("</pre>gg</body></html>");
                out.close();
        }

        *protected* *void* doPost(HttpServletRequest request,
                        HttpServletResponse response) *throws* 
ServletException, IOException {
        }

        *public* *void* destroy() {
                UtilsN1.factory = *null*;
        }
 }

 *package* com.leak;
 *public* *class* VO {
 String  name;
 *public* String getName() {
        *return* name;}
 *public* *void* setName(String name) {
        this.name = name;}
 }


-- 
*Thanks & Regards
 Vickyb

*

Reply via email to