I have a JUnit test class that is attempting to test some JPA
datastore "create" operations, and I'm getting results that *seem* to
indicate a memory leak in the EntityManagerFactory (?)  Basically, if
I use "test1a" (see below), the heap in use by the JUnit test process
continually increases until the JUnit test fails with an OutOfMemory
error.  Test1b suffers from no such problem.

I would not expect this type of behavior from test1a because even
though I'm creating a new EntityManager upon every for-loop iteration,
that "em" should go away after every for-loop iteration since the
variable reference is replaced with a new EntityManager each time.

Now, one might argue that my test is just going too fast, and the GC
isn't getting a chance to Garbage Collect.  However, Test1a takes a
pretty long time to execute on my machine (> 120 seconds), so I
*should* be getting some GC, right?  Unless the EntityManagerFactory
is holding onto a reference to each created EntityManager?

Any input here would be much appreciated...

Thanks!

david

ps - my "UserImpl" is a standard JPA entity.


///////////////////////////////
//Begin JUnit Test #1a
///////////////////////////////

User user = null;
EntityManager em = null;
for (int i = 0; i < 5000; i++)
{
  //See how I get an em here:
http://code.google.com/appengine/docs/java/datastore/usingjpa.html#Getting_an_EntityManager_Instance
  em = EMF.get().createEntityManager();
  user = new UserImpl("test" + i);
  em.persist(user);
  em.close();
}

///////////////////////////////
//End Test #1b
///////////////////////////////

///////////////////////////////
//Begin JUnit Test #1b
///////////////////////////////

User user = null;
EntityManager em = EMF.get().createEntityManager();
for(int i = 0; i < 5000; i++)
{
  user = new UserImpl("test" + i);
  em.persist(user);
}
em.close();

///////////////////////////////
//End Test #1b
///////////////////////////////

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine for Java" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.

Reply via email to