ObjectDB ObjectDB

Memory Leak?

#1

Hi,

I'm evaluating ObjectDB and certainly new to it.
I'm seeing a possible memory leak in ObjectDB or it could be my abusive use of it.
Basically I'm adding 1 million objects into it and then retrieve each of the object one by one. The object is key by Long.

Here is the jmap at time1:

num     #instances         #bytes  class name
----------------------------------------------

   1:        704422      950869896  [B
   2:       6257543      300362064  com.objectdb.o.STA
   3:        347641       72309328  com.objectdb.jdo.PMImpl
   4:        347136       50256896  [I
   5:        347641       47279176  [Lcom.objectdb.o.LRQ;
   6:        347641       47279176  [Lcom.objectdb.o.ENT;
   7:        347641       30592408  com.objectdb.o.STM
   8:        347756       27821784  [Ljava.util.HashMap$Entry;
   9:        347641       27811280  com.objectdb.o.LDR
  10:        335544       24159168  com.objectdb.o.QRQ

Here is the jmap at time1 + 1 minute:


num     #instances         #bytes  class name
----------------------------------------------

   1:        704422      953667840  [B
   2:       6781649      325519152  com.objectdb.o.STA
   3:        376758       78365664  com.objectdb.jdo.PMImpl
   4:        376758       51239088  [Lcom.objectdb.o.LRQ;
   5:        376758       51239088  [Lcom.objectdb.o.ENT;
   6:        344917       47577920  [I
   7:        376758       33154704  com.objectdb.o.STM
   8:        376870       30150944  [Ljava.util.HashMap$Entry;
   9:        376758       30140640  com.objectdb.o.LDR
  10:        753873       24416568  [Ljava.lang.Object;
  11:        335544       24159168  com.objectdb.o.QRQ

Notice com.objectdb.o.STA and other HashMap.

Here is the code that retrieves the data. I'm pretty sure I'm not holding objects that I'm using directly that causes ever expanding memory usage. I'm putting my code as a reply to this topic.

edit
delete
#2
 private void deleteData() {
  if (em.isOpen()) {
   em.close();
  }
  long fromTs = System.currentTimeMillis();
  String[] attributes = null;
  Query q1 = null;
  for (int i=0, j=0; i<deviceCount; i++) {
   if (i % threadCount != mod) {
    continue;
   }
   j++;
   attributes = generateAttributes(i);
   em = emf.createEntityManager();
   em.getTransaction().begin();
   q1 = em.createQuery("SELECT d FROM Device d WHERE d.deviceId = ?1");
   //q1 = em.createQuery("DELETE d FROM Device d WHERE d.deviceId = ?1");
   q1.setParameter(1, new Long(i));
   //q1.executeUpdate();
   Device d = (Device) q1.getSingleResult();
   //em.remove(d);
   if (j%10000==0) {
    logger("Retrieved " + j + " objects. Last object: " + d);
   }
   em.getTransaction().commit();
   em.close();
   em = emf.createEntityManager();
  }
  if (em.getTransaction().isActive()) {
   em.getTransaction().commit();
   em.close();
  }
 
  logger("Retrieved %s objects, elapsed time: %s",  deviceCount, getTsDiff(fromTs));
 
 }

 

edit
delete
#3

The heap dump indicates that there are too many EntityManager instances (PMImpl). The other instances are probably hold by the EntityManager instances, so the question is why the EntityManager instances are not released.

The code that you posted presents a partial picture. Could you please post the complete test (either as an attachment in this forum thread or in a support ticket, if you prefer not to post it publicly)?

ObjectDB Support
edit
delete
#4

I attached the files.

MyMain.java is the main class which calls TestObjectDB.java.

Also, just wanted to emphasize that I did jmap with "-histo:live", so the heap dump I posted represented live objects.

Thanks.

edit
delete
#5

Thanks. Could you please post the source code of the Device entity class?

ObjectDB Support
edit
delete
#6

I found the problem. At the end of the loop I created an EntityManager (line 115). My bad.

After I fixed it, no more memory explosion.

I attached Device.java but I guess you don't need it anymore.

edit
delete
#7

Thanks for the update.

This demonstrates that EntityManager instances must be closed and are not released automatically by the Garbage Collector.

I moved your new questions to a new thread.

ObjectDB Support
edit
delete

Reply

To post on this website please sign in.