This repository was archived by the owner on Mar 8, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +12
-3
lines changed
scala/org/bblfsh/client/v2 Expand file tree Collapse file tree 2 files changed +12
-3
lines changed Original file line number Diff line number Diff line change @@ -144,7 +144,7 @@ class ContextExt {
144144 delete (ctx);
145145
146146 if (jCtxExt)
147- getJNIEnv ()->DeleteGlobalRef (jCtxExt);
147+ getJNIEnv ()->DeleteWeakGlobalRef (jCtxExt);
148148 }
149149
150150 // lookup searches for a specific node handle.
@@ -159,7 +159,7 @@ class ContextExt {
159159 // We need this because a NodeExt from Scala side includes
160160 // a Scala ContextExt and a handle to the native C node
161161 void setJavaContext (jobject ctx) {
162- jCtxExt = getJNIEnv ()->NewGlobalRef (ctx);
162+ jCtxExt = getJNIEnv ()->NewWeakGlobalRef (ctx);
163163 }
164164
165165 // Iterate returns iterator over an external UAST tree.
Original file line number Diff line number Diff line change @@ -149,7 +149,16 @@ object BblfshClient {
149149 def decode (): ContextExt = {
150150 val bufDirectCopy = ByteBuffer .allocateDirect(buf.size)
151151 buf.copyTo(bufDirectCopy)
152- BblfshClient .decode(bufDirectCopy)
152+ val result = BblfshClient .decode(bufDirectCopy)
153+ // Sometimes the direct buffer can take a lot to deallocate,
154+ // causing Out of Memory, because it is not allocated in
155+ // in the JVM heap and will only be deallocated them when
156+ // JVM does not have more space in its heap
157+ // This line alleviates the problem
158+ // Problem can be tested if we remove it and do a
159+ // loop decoding a file
160+ System .gc()
161+ result
153162 }
154163 }
155164
You can’t perform that action at this time.
0 commit comments