File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Performance and the fly likes Memor Leak Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Performance
Bookmark "Memor Leak " Watch "Memor Leak " New topic

Memor Leak

Rashmi Trivedi
Ranch Hand

Joined: Aug 13, 2001
Posts: 60
Hi all
I have writeen program which read text file and insert each records into SQL 2000. Text file has around 200,000 records. The problem i have found is it consumes lots of memory while program is running and inserting records. The memory goes up to 256MB and start decreasing and than at some stage it throws OutOfMomory Error message.
Most of my variables are Stirng and few float. Its a very simple java application, which load jdbc driver, make conncetion to data base and prepare sql statement and so on.
I thought garbage collector should run automatically when jvm reaches max to the heap size but i think gc is not able to free enough momory for the request and therefore i got outofmomory error message.
Hope some has same kind of problem and have some kind of solutions.
Jamie Robertson
Ranch Hand

Joined: Jul 09, 2001
Posts: 1879

It sounds like your not cleaning up after yourself. Do you free up all temporary/local variables after use? Maybe the program is creating temporary objects(behind the scenes) which are not getting cleaned up?
by the way, on the topic of performance, are you executing each PreparedStatement separately or are you batching them? If you are not batching look into it, sounds like you could gain some real performance gains here!
If possible, post the code. It would make it easier to give better quality advice. Sounds like a small class anywho!

[This message has been edited by Jamie Robertson (edited August 22, 2001).]
Rashmi Trivedi
Ranch Hand

Joined: Aug 13, 2001
Posts: 60
Hi Jamie
Thank you for your reply. I solved moemory leak problem in my porgram. It was my code which was doing it. I had prepared statment in side while loop and it was causing all the problem. I took that prepared statement out side the while loop and ran the program and it worked like a dream. I would like to attach code with this response but i don't know how to attach file here.
Thank you once again for your help.
John Bateman
Ranch Hand

Joined: Mar 09, 2000
Posts: 320
You don't have to atach files (actually you can't) but you can copy and paste pieces of solutions here.
Check out the link in my signature how to do this.
Hope this helps.

SOURCE CODE should be SURROUNDED by "code" tags.
Click here for an example

SOURCE CODE should be SURROUNDED by "code" tags.
I agree. Here's the link:
subject: Memor Leak
It's not a secret anymore!