• 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

memory leak - java.lang.OutOfMemory

 
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can anyone point me to some decent approaches to isolating where a memory leak is occuring?

I'm reading an XML file (SAX) and storing it in a database. The file contains data for many class A that can contain many class B that can contain many class C. Storing classes A and B in the database seems to work fine, for the entire file. Class C gives a java.lang.OutOfMemory error after handling about 3000 to 4000. I'm not storing them in a collection, just storing them in the database and then re-using the same object to create the next instance.

What's the best way to isolate where this is occurring?

ms
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The best approach would be to use a profiler like Optimizeit or something simmilar.

Try allocating the JVM more memory first though. It might be something as simple as that.
 
drifter
Posts: 1364
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you don't already have a profiler, try Quest Software's JProbe Profiler Freeware.
[ March 09, 2005: Message edited by: Carol Enderlin ]
 
Carol Enderlin
drifter
Posts: 1364
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


...then re-using the same object to create the next instance.



You could try NOT reusing the same object. (Is the code long and complex? You could post some code snippets for more help)


Class C gives a java.lang.OutOfMemory error after handling about 3000 to 4000.



Is it really how many it has processed or is it the data for class C in the records around 3000 - 4000? Maybe those are really large?

Are you running this on an application server? More details might help in what to try.

You could also check out this: Sun's Java Tools article. It's about
HPROF: A Heap/CPU Profiling Tool in J2SE 5.0. It has a history section about tools available in previous jdk versions.
 
Mike Southgate
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the suggestions thus far. I ran a little test and created a loop that tried to save class A in the database 10000 times. It only got to 893 when it ran out of memory too. So I conclude that it's somewhere in my jdbc stuff. Should this be moved to that forum?

Anyway, here is the method being called many times:




It calls some methods in the Position class which is really just a class representing a row of data in a database. The culprits are the methods that do sql so we can focus on the store(count) method, which is listed below:



The DBConnection.getConnection() is a simple connection pooling class I've developed that just grabs existing database connections and then let's you return them to the queue when you're done with them.

ms
 
Space seems cool in the movies, but once you get out there, it is super boring. Now for a fascinating tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic