I tried below test code to see if I can clear my workspace memory. However what I see is it doesn’t clear the memory. Also using same workspace ID again after destroy result in more data usage.
I tried below code to get and destroy the workspace after using it… however I cannot use it after I destroy it. It seems Nd4j.getWorkspaceManager().getAndActivateWorkspace doesn’t create the workspace again. Also the error raised say Can't allocate memory: Workspace is full
This results in not being able to allocate memory on 4th try…
Physical bytes - before: 538MB
Physical bytes - after 1x: 5658MB
Physical bytes - after 2x: 5658MB
Physical bytes - after 3x: 5658MB
Physical bytes - after workspace.destroyWorkspace(): 538MB
Physical bytes - after close + 1 sec: 538MB
org.nd4j.linalg.exception.ND4JIllegalStateException: Can't allocate memory: Workspace is full
at org.nd4j.linalg.memory.abstracts.Nd4jWorkspace.alloc(Nd4jWorkspace.java:442)
at org.nd4j.linalg.memory.abstracts.Nd4jWorkspace.alloc(Nd4jWorkspace.java:322)
at org.nd4j.linalg.api.buffer.BaseDataBuffer.<init>(BaseDataBuffer.java:818)
at org.nd4j.linalg.api.buffer.FloatBuffer.<init>(FloatBuffer.java:58)
at org.nd4j.linalg.api.buffer.factory.DefaultDataBufferFactory.create(DefaultDataBufferFactory.java:326)
at org.nd4j.linalg.factory.Nd4j.createBuffer(Nd4j.java:1455)
at org.nd4j.linalg.api.ndarray.BaseNDArray.<init>(BaseNDArray.java:341)
at org.nd4j.linalg.cpu.nativecpu.NDArray.<init>(NDArray.java:185)
at org.nd4j.linalg.cpu.nativecpu.CpuNDArrayFactory.create(CpuNDArrayFactory.java:231)
at org.nd4j.linalg.factory.Nd4j.create(Nd4j.java:4274)
at org.nd4j.linalg.factory.Nd4j.create(Nd4j.java:3962)
at xxxxxx.testWithMemoryWorkSpacesWithDestroy(ClassifyFromMultipleThreadsTest.java:287)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.junit.runner.JUnitCore.run(JUnitCore.java:160)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
Same result even if I use Nd4j.getWorkspaceManager().getWorkspaceForCurrentThread("TestWorkSpaceID").destroyWorkspace();