postgresql-jdbc.git / summary / log / commit / refs
commit d7cab7bd86e4adde0aa0a2fb4a6dfed59cf05cd8
Author: Vladimir Sitnikov <sitnikov.vladimir@gmail.com>
Date: Mon Oct 12 15:57:54 2015 +0000
fix: avoid memory leak when redeploying pgjdbc
FAST_NUMBER_FAILED is used as a control-flow-exception pattern, thus it does not require a stacktrace.
It turns out Throwable might store strong reference to a class, thus it might result in OutOfMemory
closes #394
org/postgresql/jdbc2/AbstractJdbc2ResultSet.java | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/org/postgresql/jdbc2/AbstractJdbc2ResultSet.java b/org/postgresql/jdbc2/AbstractJdbc2ResultSet.java
index 9c61e375..f98fd9c4 100644
--- a/org/postgresql/jdbc2/AbstractJdbc2ResultSet.java
+++ b/org/postgresql/jdbc2/AbstractJdbc2ResultSet.java
@@ -2217,7 +2217,18 @@ public abstract class AbstractJdbc2ResultSet implements BaseResultSet, org.postg
* the exception is always caught and is not visible to users.
*/
private static final NumberFormatException FAST_NUMBER_FAILED =
- new NumberFormatException();
+ new NumberFormatException() {
+
+ // Override fillInStackTrace to prevent memory leak via Throwable.backtrace hidden field
+ // The field is not observable via reflection, however when throwable contains stacktrace, it does
+ // hold strong references to user objects (e.g. classes -> classloaders), thus it might lead to
+ // OutOfMemory conditions.
+ @Override
+ public synchronized Throwable fillInStackTrace()
+ {
+ return this;
+ }
+ };
/**
* Optimised byte[] to number parser. This code does not
[parent: a194c5e5429b]