2

I have simple web app using :

1-Spring mvc4.1.1

2-hibernate 4.3.10

3-servlet 3.1

4-Oracle 12c

5-Ojdbc6 (it existed in tomcat/lib NOT in app/lib)

6-JPA 2.1

my persistence xml is :

<?xml version="1.0" encoding="UTF-8"?>

<persistence-unit name="NewpersistenceUnit">
    <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
    <mapping-file>com/springapp/mvc/DBManagement/EntityMapping.xml</mapping-file>
    <class>com.springapp.mvc.DBManagement.StateEntity</class>
    <properties>
        <property name="hibernate.connection.url" value="jdbc:oracle:thin:@//localhost:1521/orcl"/>
        <property name="hibernate.connection.driver_class" value="oracle.jdbc.OracleDriver"/>
        <property name="hibernate.connection.username" value="system"/>
        <property name="hibernate.connection.password" value="1234546"/>
        <property name="hibernate.archive.autodetection" value="class"/>
        <property name="hibernate.show_sql" value="true"/>
        <property name="hibernate.format_sql" value="true"/>
        <property name="hbm2ddl.auto" value="update"/>
        <property name="hibernate.connection.oracle.jdbc.V8Compatible" value="true"/>
        <property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect"/>
    </properties>
</persistence-unit>

insert method is

    public void AddLocation()
{
    EntityManagerFactory emf= Persistence.createEntityManagerFactory("NewpersistenceUnit");
    EntityManager em= emf.createEntityManager();
    EntityTransaction et= em.getTransaction();

    LocationEntity location = new LocationEntity();

    location.setCityname("Newyork");

    et.begin();
    em.persist(location);
    et.commit();
    em.close();

}

when i deploy and undeployed in tomcat8.0.26 and make memory leak please help me

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • What makes you sure, that you have a memory leak? It's not an unusual behavior that the memory increases after each redeployment because the garbage collector may release the memory just after some time. You could try to reduce the MaxPermSize so that the garbage collector is forced to release the perm space earlier, that is used by classes loaded trough tomcats WebappClassLoaders – eztam Dec 04 '15 at 13:40

1 Answers1

2

In my experience this is in most cases caused by existing strong references to tomcats WebappClassLoader. One of the used libraries or your application has a strong reference to the WebappClassLoader that prevents the WebappClassLoader from being garbage collected. Tracking down such a memory leak could be done following these steps:

  • Start tomcat with your application
  • Redeploy your application once
  • Manually run a garbage collection and create a heapdump (can be done with visualvm)
  • Analyse your heapdump with a profile like Eclipse Memory Analyser or JProfiler
  • Find an instance of the type WebappClassLoader that has an attribute started=false
  • Trace the GC roots for these instance of WebappClassLoader (excluding weak, soft and phantom references)
  • Now you should see what causes the WebappClassLoader to stay alive and be prevented from GC

Here is a more detailed explanation: How to analyze leaky webapps

eztam
  • 3,443
  • 7
  • 36
  • 54