0

I have a webcrawler thar uses a connection pool to connect to database and insert pages.

I saw that the memory usage is increasing while the program executes. I guess that I forgot to close some PreparedStatement or another object of the connection.

I call the connection.close method, but it only returns the connectin to the database.

There is a way to see if there are opened objects in the connection?

1
  • How do you know it's using a lot of memory? Is this from top, and is it SHR? It's normal for SHR to grow to equal the size of shared_buffers over time, and not a problem. Show your evidence of memory usage please Commented Jul 13, 2011 at 22:08

1 Answer 1

1

You seem to suggest that your application has a memory leak. To begin debugging, you can use jmap, a utility that comes with the JDK (usually found on the bin directory next to java, javac, javadoc, ...etc). This command will produce a memory map of all objects sitting in your JVM. You can run it over time as your application is running and compare object counts to see if there is any type of object that seems to have a continuously increasing total count, but no reductions (as a result of Garbage Collections).

jmap -heap -histo <PROCESS_ID_OF_YOUR JVM>

If you are indeed not closing your statement objects properly, you will quickly see them bubble up to the top of your stack.

All "closable" objects should be closed in finally blocks to avoid leaving open connections, statements, ...etc lingering in the JVM if an exception is thrown before you get to the close.

note: on windows, these executables have the .exe suffix.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.