# Destroy Neural Network completely (Memory Leak)

**URL:** <https://community.konduit.ai/t/destroy-neural-network-completely-memory-leak/1009>\
**Category:** DL4J\
**Created:** [November 23, 2020, 8:11pm UTC](https://community.konduit.ai/t/destroy-neural-network-completely-memory-leak/1009 "2020-11-23T20:11:25Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Demo](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/demo/32/303_2.png) [@Demo](https://community.konduit.ai/u/Demo)\
**Post date:** [November 23, 2020, 8:11pm UTC](https://community.konduit.ai/t/destroy-neural-network-completely-memory-leak/1009/1 "2020-11-23T20:11:25Z")

</div>

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)?

---

<div class="post-metadata">

**Author:** ![agibsonccc](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/agibsonccc/32/697_2.png) [@agibsonccc](https://community.konduit.ai/u/agibsonccc)\
**Post date:** [November 26, 2020, 10:22pm UTC](https://community.konduit.ai/t/destroy-neural-network-completely-memory-leak/1009/2 "2020-11-26T22:22:41Z")

</div>

@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

---

<div class="post-metadata">

**Author:** ![saudet](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/saudet/32/69_2.png) [@saudet](https://community.konduit.ai/u/saudet)\
**Post date:** [November 27, 2020, 12:17am UTC](https://community.konduit.ai/t/destroy-neural-network-completely-memory-leak/1009/3 "2020-11-27T00:17:33Z")

</div>

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