• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Toplink memory problem

 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

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.

Can anybody tell me what the problem is?

Thanks.
Cris.
 
author
Posts: 304
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Cris,

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)?

-Mike
 
Cristian Popovici
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Mike, thanks for the answer.

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.

Regards,
Cris.
 
Mike Keith
author
Posts: 304
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Cris,

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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic