Skip to content

Commit 527fa24

Browse files
committed
[CORE] Fix to the Session memory management.
1 parent 56cd842 commit 527fa24

File tree

1 file changed

+3
-1
lines changed
  • modules/api/src/main/scala/org/platanios/tensorflow/api/core/client

1 file changed

+3
-1
lines changed

modules/api/src/main/scala/org/platanios/tensorflow/api/core/client/Session.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,13 +188,15 @@ object Session {
188188
sessionConfig.map(_.configProto.toByteArray).orNull)
189189
val nativeHandleWrapper = NativeHandleWrapper(nativeHandle)
190190
val closeFn = () => {
191+
graphReference.close()
191192
nativeHandleWrapper.Lock.synchronized {
192193
if (nativeHandleWrapper.handle != 0) {
193-
NativeTensor.eagerDelete(nativeHandleWrapper.handle)
194+
NativeSession.delete(nativeHandleWrapper.handle)
194195
nativeHandleWrapper.handle = 0
195196
}
196197
}
197198
}
199+
graph.nativeHandleWrapper.addPreCleanupFunction(closeFn)
198200
val session = new Session(graphReference, target, nativeHandleWrapper, closeFn)
199201
// Keep track of references in the Scala side and notify the native library when the session is not referenced
200202
// anymore anywhere in the Scala side. This will let the native library free the allocated resources and prevent a

0 commit comments

Comments
 (0)