Destroy Neural Network completely (Memory Leak)

I am writing a genetic algorithm which generates several neural networks and calculates their fitness. After that the neural network is not needed anymore and can be removed. However, they seem to stay alive in the off-heap memory and thus leading to a memory leak after a while. How can I destroy / remove the neural network completely after receiving the fitness value (evaluation)?

@Demo you can release the INDArrays if you run it within a try/with resources block.

For some aspects of this it might involve javacpp though, I would defer to @saudet here

What you’re looking for are “workspaces”: https://deeplearning4j.konduit.ai/config/config-memory/config-workspaces