• 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

MySQL memory leak

 
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I originally posted an eraly version of this question in the java intermediate forum, but investigation indicates its in the jdbc...

I'm getting a java.lang.OutOfMemoryError after calling this method around 4000 times:


As a test I created a loop that went 10000 times and gradually added lines from the above method to see when it blows up. As it turns out, the offending line is : ps.executeUpdate();

I'm using mysql. Any suggestions on how to proceed. Would unloading and reloading the mysql driver help?

Has anyone else out there used mysql with thousands of inserts?

ms
 
Ranch Hand
Posts: 1071
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Wild guess, maybe make the PreparedStatement a class level variable so only one instance is made.

Also move the ps.close() to a finally block. (but if you haven't been seeing any exceptions this probabaly isn't a problem).

On second thought maybe the PS isn't a problem but it looks like you are getting a new connection each time and not closing it. Just guesses, I'm not a JDBC guru by any means.
[ March 09, 2005: Message edited by: Steven Bell ]
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Mike,
A few comments:
1) Try executing the loop with a different prepared statement. For example, try with one that just does a select. This will provide more clues as to the problem.
2) If you are calling this alot of times in production, consider not making it synchronized or executing multiple inserts in a batch.
3) The "ps = null" statement doesn't do anything as the ps variable is about to go out of scope anyway. This isn't the problem, but it's good to know.
 
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

Originally posted by Jeanne Boyarsky:
Mike,
A few comments:
1) Try executing the loop with a different prepared statement. For example, try with one that just does a select. This will provide more clues as to the problem.
2) If you are calling this alot of times in production, consider not making it synchronized or executing multiple inserts in a batch.
3) The "ps = null" statement doesn't do anything as the ps variable is about to go out of scope anyway. This isn't the problem, but it's good to know.



Thanks for the input. Re # 3, that is actually left over code from when I thought the issue might be garbage collection and was trying to force earlier cleanup.
I made it synchronized to allow for multi-threading, though that isn't an issue yet.
Batching the inserts is a good idea, that might at least reduce the issue.
I'll also try using selects instead.
One last thing is this used to work OK before I started using the JRE that came with J2EE. I think I'll give 1.5 a shot and see what happens.

ms
 
So you made a portal in time and started grabbing people. This tiny ad thinks that's rude:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic