OutOfMemory – GC OverHead exceeded – Not closing prepared statements – JDBC with Oracle 11g

I wrote a unit test using Spring and for datasource, I used org.springframework.jdbc.datasource.SingleConnectionDataSource. This unit test was calling a legacy code in loop for 5000 times. After 3000 iterations, it was throwing a OutOfMemory (OOM) error. After further research, it turned out to be an issue with legacy code that this unit test was calling that didn’t close prepared statements. And since this is a ‘single connection’ datasource, I never got the ‘connections exhausted’ error. Looks like when ever you call a connection.prepareStatement, the connection object created a few objects and stored them in. As a result, the connection object grew in size and eventually we got the OOM error. Closing the prepared statement fixed the issue.

Before this incident, I didn’t think we could have memory leaks if a statement is not closed.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: