I have a web application which uses Hibernate + OpenJPA for database connection. When this application is undeployed using tomcat manager, and then when we take a memory dump and check the class objects in the dump I see many Hibernate, Log4j and servlet class object in the dump. Even though when I am calling the proper shutdown for each of them. Here is the code which I am using to shutdown them. It is called in contextDestroyed(ServletContextEvent sce)
EntityManager em = EntityManagerHelper.getEntityManager();
/* Get a session.*/
Session session = (Session) em.getDelegate();
System.out.println("Calling session close.");
closeSessionFactory(session.getSessionFactory());
System.out.println("Closing EntityMnanager.");
EntityManagerHelper.closeEntityManagerFactory();
System.out.println("De-registering the JDBC drivers.");
deregisterJDBCDrivers();
System.out.println("Shutting down log4j.");
org.apache.log4j.LogManager.shutdown();
Why I am still seeing the class object in the dump after calling the shutdown/close method calls? How to prevent it?