• 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
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

Toplink causes memory leak?

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

I am getting Hava heap memory error on a select statement for large database table. The table contains approximately 50,000 records.
The entity that I ma fetching from the database has many fields.
I used jProbe to find the memory leak and found out that there were som many Object [] and char[] that were hanging in the heap memory. The were bound to some classes in Toplink.

Can it be avoided? I am getting the entities in chucnk so as to reindex the database entity.

Thanks and Regards,
Girish
 
Girish Vasmatkar
Ranch Hand
Posts: 201
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello again,

Can someone please help me solving the issue? Can changing version number of toplink solve the issue?
 
Ranch Hand
Posts: 263
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your options:
1. Do not select all rows/data from the table. Select only what you need.
2. Turn off Caching.
 
Ranch Hand
Posts: 553
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do you run out of memory on single select from the table? Or are you loosing memory over time?

If it is the single select, then it is not a memory leak, you are just trying to read too much data for your JVM.
Either increase your heap size, or read less data.

In JPA you can chunk a query result using JPA Query setFirstResult and setMaxResult.
In TopLink/EclipseLink you can also use a ScrollableCursor.

If reading into the same EntityManager, ensure you clear it between pages otherwise you can still run out of memory. Or get a new EntityManager per page.
 
Girish Vasmatkar
Ranch Hand
Posts: 201
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First of all, thanks for the reply
My database table has about 50,000 records and I am getting those records in chunk exactly the way you menyioned.



If it is the single select, then it is not a memory leak, you are just trying to read too much data for your JVM.
Either increase your heap size, or read less data.

In JPA you can chunk a query result using JPA Query setFirstResult and setMaxResult.
In TopLink/EclipseLink you can also use a ScrollableCursor.





But as I get more and more data for example first 100 then next 100 ...I see on the task manager the memory consumption increasing gradually....
and after about 23,000 records are fetched the JVM blows up and OutOfMemory exception occurs.
Right now I am using same EntityManager for the whole select and I will try to get the select now witha new EntityManager per page.


Thanks and Regards,
Girish

 
Eliminate 95% of the weeds in your lawn by mowing 3 inches or higher. Then plant tiny ads:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic