Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 49740c5

Browse files
committed
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
1 parent a057cbe commit 49740c5

File tree

4 files changed

+16
-14
lines changed

4 files changed

+16
-14
lines changed

src/interfaces/jdbc/org/postgresql/jdbc1/PreparedStatement.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ public void setBoolean(int parameterIndex, boolean x) throws SQLException
164164
*/
165165
public void setByte(int parameterIndex, byte x) throws SQLException
166166
{
167-
set(parameterIndex, (new Integer(x)).toString());
167+
set(parameterIndex, Integer.toString(x));
168168
}
169169

170170
/**
@@ -177,7 +177,7 @@ public void setByte(int parameterIndex, byte x) throws SQLException
177177
*/
178178
public void setShort(int parameterIndex, short x) throws SQLException
179179
{
180-
set(parameterIndex, (new Integer(x)).toString());
180+
set(parameterIndex, Integer.toString(x));
181181
}
182182

183183
/**
@@ -190,7 +190,7 @@ public void setShort(int parameterIndex, short x) throws SQLException
190190
*/
191191
public void setInt(int parameterIndex, int x) throws SQLException
192192
{
193-
set(parameterIndex, (new Integer(x)).toString());
193+
set(parameterIndex, Integer.toString(x));
194194
}
195195

196196
/**
@@ -203,7 +203,7 @@ public void setInt(int parameterIndex, int x) throws SQLException
203203
*/
204204
public void setLong(int parameterIndex, long x) throws SQLException
205205
{
206-
set(parameterIndex, (new Long(x)).toString());
206+
set(parameterIndex, Long.toString(x));
207207
}
208208

209209
/**
@@ -216,7 +216,7 @@ public void setLong(int parameterIndex, long x) throws SQLException
216216
*/
217217
public void setFloat(int parameterIndex, float x) throws SQLException
218218
{
219-
set(parameterIndex, (new Float(x)).toString());
219+
set(parameterIndex, Float.toString(x));
220220
}
221221

222222
/**
@@ -229,7 +229,7 @@ public void setFloat(int parameterIndex, float x) throws SQLException
229229
*/
230230
public void setDouble(int parameterIndex, double x) throws SQLException
231231
{
232-
set(parameterIndex, (new Double(x)).toString());
232+
set(parameterIndex, Double.toString(x));
233233
}
234234

235235
/**

src/interfaces/jdbc/org/postgresql/jdbc1/ResultSet.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,8 @@ public boolean next() throws SQLException
127127
*/
128128
public void close() throws SQLException
129129
{
130-
// No-op
130+
//release resources held (memory for tuples)
131+
rows.setSize(0);
131132
}
132133

133134
/**

src/interfaces/jdbc/org/postgresql/jdbc2/PreparedStatement.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ public void setBoolean(int parameterIndex, boolean x) throws SQLException
164164
*/
165165
public void setByte(int parameterIndex, byte x) throws SQLException
166166
{
167-
set(parameterIndex, (new Integer(x)).toString());
167+
set(parameterIndex, Integer.toString(x));
168168
}
169169

170170
/**
@@ -177,7 +177,7 @@ public void setByte(int parameterIndex, byte x) throws SQLException
177177
*/
178178
public void setShort(int parameterIndex, short x) throws SQLException
179179
{
180-
set(parameterIndex, (new Integer(x)).toString());
180+
set(parameterIndex, Integer.toString(x));
181181
}
182182

183183
/**
@@ -190,7 +190,7 @@ public void setShort(int parameterIndex, short x) throws SQLException
190190
*/
191191
public void setInt(int parameterIndex, int x) throws SQLException
192192
{
193-
set(parameterIndex, (new Integer(x)).toString());
193+
set(parameterIndex, Integer.toString(x));
194194
}
195195

196196
/**
@@ -203,7 +203,7 @@ public void setInt(int parameterIndex, int x) throws SQLException
203203
*/
204204
public void setLong(int parameterIndex, long x) throws SQLException
205205
{
206-
set(parameterIndex, (new Long(x)).toString());
206+
set(parameterIndex, Long.toString(x));
207207
}
208208

209209
/**
@@ -216,7 +216,7 @@ public void setLong(int parameterIndex, long x) throws SQLException
216216
*/
217217
public void setFloat(int parameterIndex, float x) throws SQLException
218218
{
219-
set(parameterIndex, (new Float(x)).toString());
219+
set(parameterIndex, Float.toString(x));
220220
}
221221

222222
/**
@@ -229,7 +229,7 @@ public void setFloat(int parameterIndex, float x) throws SQLException
229229
*/
230230
public void setDouble(int parameterIndex, double x) throws SQLException
231231
{
232-
set(parameterIndex, (new Double(x)).toString());
232+
set(parameterIndex, Double.toString(x));
233233
}
234234

235235
/**

src/interfaces/jdbc/org/postgresql/jdbc2/ResultSet.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,8 @@ public boolean next() throws SQLException
128128
*/
129129
public void close() throws SQLException
130130
{
131-
// No-op
131+
//release resources held (memory for tuples)
132+
rows.setSize(0);
132133
}
133134

134135
/**

0 commit comments

Comments
 (0)