Commit 49740c5f authored by Bruce Momjian's avatar Bruce Momjian

Attached are patches for two fixes to reduce memory usage by the JDBC

drivers.

The first fix fixes the PreparedStatement object to not allocate
unnecessary objects when converting native types to Stings.  The old
code used the following format:
        (new Integer(x)).toString()
whereas this can more efficiently be occompilshed by:
        Integer.toString(x);
avoiding the unnecessary object creation.

The second fix is to release some resources on the close() of a
ResultSet.  Currently the close() method on ResultSet is a noop.  The
purpose of the close() method is to release resources when the ResultSet
is no longer needed.  The fix is to free the tuples cached by the
ResultSet when it is closed (by clearing out the Vector object that
stores the tuples).  This is important for my application, as I have a
cache of Statement objects that I reuse.  Since the Statement object
maintains a reference to the ResultSet and the ResultSet kept references
to the old tuples, my cache was holding on to a lot of memory.

Barry Lind
parent a057cbec
...@@ -164,7 +164,7 @@ public class PreparedStatement extends Statement implements java.sql.PreparedSta ...@@ -164,7 +164,7 @@ public class PreparedStatement extends Statement implements java.sql.PreparedSta
*/ */
public void setByte(int parameterIndex, byte x) throws SQLException public void setByte(int parameterIndex, byte x) throws SQLException
{ {
set(parameterIndex, (new Integer(x)).toString()); set(parameterIndex, Integer.toString(x));
} }
/** /**
...@@ -177,7 +177,7 @@ public class PreparedStatement extends Statement implements java.sql.PreparedSta ...@@ -177,7 +177,7 @@ public class PreparedStatement extends Statement implements java.sql.PreparedSta
*/ */
public void setShort(int parameterIndex, short x) throws SQLException public void setShort(int parameterIndex, short x) throws SQLException
{ {
set(parameterIndex, (new Integer(x)).toString()); set(parameterIndex, Integer.toString(x));
} }
/** /**
...@@ -190,7 +190,7 @@ public class PreparedStatement extends Statement implements java.sql.PreparedSta ...@@ -190,7 +190,7 @@ public class PreparedStatement extends Statement implements java.sql.PreparedSta
*/ */
public void setInt(int parameterIndex, int x) throws SQLException public void setInt(int parameterIndex, int x) throws SQLException
{ {
set(parameterIndex, (new Integer(x)).toString()); set(parameterIndex, Integer.toString(x));
} }
/** /**
...@@ -203,7 +203,7 @@ public class PreparedStatement extends Statement implements java.sql.PreparedSta ...@@ -203,7 +203,7 @@ public class PreparedStatement extends Statement implements java.sql.PreparedSta
*/ */
public void setLong(int parameterIndex, long x) throws SQLException public void setLong(int parameterIndex, long x) throws SQLException
{ {
set(parameterIndex, (new Long(x)).toString()); set(parameterIndex, Long.toString(x));
} }
/** /**
...@@ -216,7 +216,7 @@ public class PreparedStatement extends Statement implements java.sql.PreparedSta ...@@ -216,7 +216,7 @@ public class PreparedStatement extends Statement implements java.sql.PreparedSta
*/ */
public void setFloat(int parameterIndex, float x) throws SQLException public void setFloat(int parameterIndex, float x) throws SQLException
{ {
set(parameterIndex, (new Float(x)).toString()); set(parameterIndex, Float.toString(x));
} }
/** /**
...@@ -229,7 +229,7 @@ public class PreparedStatement extends Statement implements java.sql.PreparedSta ...@@ -229,7 +229,7 @@ public class PreparedStatement extends Statement implements java.sql.PreparedSta
*/ */
public void setDouble(int parameterIndex, double x) throws SQLException public void setDouble(int parameterIndex, double x) throws SQLException
{ {
set(parameterIndex, (new Double(x)).toString()); set(parameterIndex, Double.toString(x));
} }
/** /**
......
...@@ -127,7 +127,8 @@ public class ResultSet extends org.postgresql.ResultSet implements java.sql.Resu ...@@ -127,7 +127,8 @@ public class ResultSet extends org.postgresql.ResultSet implements java.sql.Resu
*/ */
public void close() throws SQLException public void close() throws SQLException
{ {
// No-op //release resources held (memory for tuples)
rows.setSize(0);
} }
/** /**
......
...@@ -164,7 +164,7 @@ public class PreparedStatement extends Statement implements java.sql.PreparedSta ...@@ -164,7 +164,7 @@ public class PreparedStatement extends Statement implements java.sql.PreparedSta
*/ */
public void setByte(int parameterIndex, byte x) throws SQLException public void setByte(int parameterIndex, byte x) throws SQLException
{ {
set(parameterIndex, (new Integer(x)).toString()); set(parameterIndex, Integer.toString(x));
} }
/** /**
...@@ -177,7 +177,7 @@ public class PreparedStatement extends Statement implements java.sql.PreparedSta ...@@ -177,7 +177,7 @@ public class PreparedStatement extends Statement implements java.sql.PreparedSta
*/ */
public void setShort(int parameterIndex, short x) throws SQLException public void setShort(int parameterIndex, short x) throws SQLException
{ {
set(parameterIndex, (new Integer(x)).toString()); set(parameterIndex, Integer.toString(x));
} }
/** /**
...@@ -190,7 +190,7 @@ public class PreparedStatement extends Statement implements java.sql.PreparedSta ...@@ -190,7 +190,7 @@ public class PreparedStatement extends Statement implements java.sql.PreparedSta
*/ */
public void setInt(int parameterIndex, int x) throws SQLException public void setInt(int parameterIndex, int x) throws SQLException
{ {
set(parameterIndex, (new Integer(x)).toString()); set(parameterIndex, Integer.toString(x));
} }
/** /**
...@@ -203,7 +203,7 @@ public class PreparedStatement extends Statement implements java.sql.PreparedSta ...@@ -203,7 +203,7 @@ public class PreparedStatement extends Statement implements java.sql.PreparedSta
*/ */
public void setLong(int parameterIndex, long x) throws SQLException public void setLong(int parameterIndex, long x) throws SQLException
{ {
set(parameterIndex, (new Long(x)).toString()); set(parameterIndex, Long.toString(x));
} }
/** /**
...@@ -216,7 +216,7 @@ public class PreparedStatement extends Statement implements java.sql.PreparedSta ...@@ -216,7 +216,7 @@ public class PreparedStatement extends Statement implements java.sql.PreparedSta
*/ */
public void setFloat(int parameterIndex, float x) throws SQLException public void setFloat(int parameterIndex, float x) throws SQLException
{ {
set(parameterIndex, (new Float(x)).toString()); set(parameterIndex, Float.toString(x));
} }
/** /**
...@@ -229,7 +229,7 @@ public class PreparedStatement extends Statement implements java.sql.PreparedSta ...@@ -229,7 +229,7 @@ public class PreparedStatement extends Statement implements java.sql.PreparedSta
*/ */
public void setDouble(int parameterIndex, double x) throws SQLException public void setDouble(int parameterIndex, double x) throws SQLException
{ {
set(parameterIndex, (new Double(x)).toString()); set(parameterIndex, Double.toString(x));
} }
/** /**
......
...@@ -128,7 +128,8 @@ public class ResultSet extends org.postgresql.ResultSet implements java.sql.Resu ...@@ -128,7 +128,8 @@ public class ResultSet extends org.postgresql.ResultSet implements java.sql.Resu
*/ */
public void close() throws SQLException public void close() throws SQLException
{ {
// No-op //release resources held (memory for tuples)
rows.setSize(0);
} }
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment