I am using Sun app server v9 and toplink as my provider for persistence. The problem is when i persist some amount of entities, the heap size of my app server is increasing dramaticly. I have updated my toplinks libs to the latest version from oracle's website.
That's a tough one. Your heap could be increasing due to any one of a whole host of reasons, and without knowing anything about your application, diagnosing your problem will be pretty difficult.
What you can do, though, is ask yourself a few questions to help track down what is happening in your app.
- How many objects are being persisted? Does "some amount" mean 10, or 10,000? - Are you using a single transaction to persist all of your objects or are they persisted across multiple transactions? - Are you using the same EntityManager (if using JPA) or UnitOfWork (if using native TopLink API) to do all of your work? - Is your application possibly maintaining references to your objects (preventing them from being collected)?
I am persisting around 1,000 objects; Basicly I am looping through a collection,instantiate the entity and then persist it with the same entity manager. The memory just jumps when i call
If i don't call this methods (not persisting the objects) no memory is used and the application ends ok. I am usin JPA and EntityManager with TopLink.
Thanks again for your help.
Joined: Jul 14, 2005
By using the same EntityManager (and maybe even the same transaction if your tx is started outside the loop) you are causing your persistence context to grow and keep all of the objects. 1000 objects is going to be a noticable piece of memory and inserting this number of entities is probably not a common scenario. Nevertheless, clearing or closing the EntityManager afterwards should cause most of the memory to be regained (modulo the shared cache if it is not disabled).
Another test that you can try is to chunk the inserts, i.e. put an object persist inside a loop of 100 and nest that inside a loop of 10 iterations, creating a new EntityManager and transaction for each of the 10 iterations. Make sure that you either clear the EntityManager at the beginning of each of the 10 iterations, or close the old one and create a new one. You should see that the memory is only increasing by the size of 100 objects at a time and, if the GC runs in a timely manner, you should see it drop again at each iteration.