During import big logs we are observed some memory leaks inside of ObjectDb, so, could you explain what we did incorrectly or investigate how to fix it ASAP.
Source code which causing memory leaks:
m_EntityMgrFactory = Persistence.createEntityManagerFactory( "objectdb:" + aFilename ); m_EntityManager = m_EntityMgrFactory.createEntityManager(); m_EntityManager.setFlushMode( FlushModeType.COMMIT ); if ( m_EntityManager.isOpen() ) { m_EntityManager.getTransaction().begin(); for ( Pa3DataKey dataKey : aDataKeys ) { m_EntityManager.persist( dataKey ); } m_EntityManager.getTransaction().commit(); m_EntityManager.flush(); m_EntityManager.clear(); m_EntityManager.close(); }
After executing code above (write a 10-15 Mbytes) need to check remaining memory in any available profiler. Stack trace for mentioned code below:
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+------------------+----------------------+ | Name | Objects | Size | +-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+------------------+----------------------+ | +---<Objects without allocation information> | 411,085 | 104,054,912 | | | | | | | +---<All threads> | 28,939 100 % | 16,588,016 100 % | | | | | | | +---java.lang.Thread.run() | 21,513 74 % | 8,151,472 49 % | | | | | | | | | +---com.anritsu.pa3.plugins.imports.ttcn3xml.parsers.TTCN3XmlParser.run() | 11,760 41 % | 4,261,872 26 % | | | | | | | | | | | +---com.anritsu.pa3.plugins.imports.ttcn3xml.parsers.TTCN3XmlParser.parse(InputStream) | 11,137 38 % | 4,169,136 25 % | | | | | | | | | | | | | +---com.anritsu.pa3.application.pa3datastore.AppLogSessionWriter.writeDataKey(Pa3DataKey) | 9,568 33 % | 3,633,880 22 % | | | | | | | | | | | | | | | +---com.anritsu.pa3.application.pa3datastore.AppLogSessionWriter.flushDataKeys() | 9,568 33 % | 3,633,880 22 % | | | | | | | | | | | | | | | +---com.anritsu.pa3.application.pa3datastore.AppLogSessionWriter.addDataKeys(Collection) | 9,568 33 % | 3,633,880 22 % | | | | | | | | | | | | | | | +---com.objectdb.jpa.EMImpl.commit() | 8,072 28 % | 3,609,944 22 % | | | | | | | | | | | | | | | +---com.objectdb.jpa.EMImpl.persist(Object) | 1,496 5 % | 23,936 0 % | | | | | | | | | +-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+------------------+----------------------+