Skip to content

Commit ae1fccf

Browse files
Fix memory leak in long-running sessions (#389)
## What is the goal of this PR? A long running session used to keep the reference to each closed transaction, continually growing in size. These references are inaccessible from outside the session object. The problem was compounded in the write transactions, when the caller did not collect the responses received after insert queries, which were held onto by the closed transaction objects. We now dispose of the closed transaction objects and free their memory. ## What are the changes implemented in this PR? Transaction now keeps a backreference to the session that spawned it and notifies it when it is closed. The session releases the reference to the transaction and allows the GC to free the memory.
1 parent 620dfd1 commit ae1fccf

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

connection/TypeDBSessionImpl.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,10 @@ public void close() {
161161
}
162162
}
163163

164+
void closed(TypeDBTransaction.Extended typeDBTransaction) {
165+
transactions.remove(typeDBTransaction);
166+
}
167+
164168
private class PulseTask extends TimerTask {
165169

166170
@Override

connection/TypeDBTransactionImpl.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050

5151
public class TypeDBTransactionImpl implements TypeDBTransaction.Extended {
5252

53+
private final TypeDBSessionImpl session;
5354
private final TypeDBTransaction.Type type;
5455
private final TypeDBOptions options;
5556
private final ConceptManager conceptMgr;
@@ -58,6 +59,7 @@ public class TypeDBTransactionImpl implements TypeDBTransaction.Extended {
5859

5960
private final BidirectionalStream bidirectionalStream;
6061
TypeDBTransactionImpl(TypeDBSessionImpl session, ByteString sessionId, Type type, TypeDBOptions options) {
62+
this.session = session;
6163
this.type = type;
6264
this.options = options;
6365
conceptMgr = new ConceptManagerImpl(this);
@@ -151,5 +153,6 @@ public void rollback() {
151153
@Override
152154
public void close() {
153155
bidirectionalStream.close();
156+
session.closed(this);
154157
}
155158
}

0 commit comments

Comments
 (0)