# Memory Leak in TVM Run on x64 linux

**URL:** <https://discuss.tvm.apache.org/t/memory-leak-in-tvm-run-on-x64-linux/9518>\
**Category:** Development\
**Created:** [March 25, 2021, 7:44am UTC](https://discuss.tvm.apache.org/t/memory-leak-in-tvm-run-on-x64-linux/9518 "2021-03-25T07:44:50Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![iftaken](https://discuss.tvm.apache.org/user_avatar/discuss.tvm.apache.org/iftaken/32/2201_2.png) [@iftaken](https://discuss.tvm.apache.org/u/iftaken)\
**Post date:** [March 25, 2021, 7:44am UTC](https://discuss.tvm.apache.org/t/memory-leak-in-tvm-run-on-x64-linux/9518/1 "2021-03-25T07:44:50Z")

</div>

Hi Experts， As the title say，I found some memory leak in TVM. I use the code from github offical, i build it from source.

git commit: 3ba586803ac7956813177aebf8072e7d7c0ab9b2

I test tvm with onnxmodel:

```python
import onnx
import numpy as np
import tvm
from tvm import te
import tvm.relay as relay

# https://github.com/onnx/models/tree/master/vision/classification/squeezenet
path = r"model/squeezenet1.1-7.onnx"
model = onnx.load(path)
input_name = "data"
shape_dict = {input_name: [1, 3, 224, 224]}
mod, params = relay.frontend.from_onnx(model, shape_dict)

target = "llvm -mcpu=core-avx2"
with relay.build_config(opt_level=3, required_pass=["FastMath"]):
    graph, lib, cparams = relay.build(mod, target, params=params)

import tvm.contrib.graph_runtime as runtime
ctx = tvm.cpu()
rt = runtime.create(graph, lib, ctx)
rt.set_input(**cparams)
inp_data = tvm.nd.array(np.random.uniform(size=(1, 3, 224, 224)).astype(np.float32))
rt.set_input(decoder_inp=inp_data)

import os, psutil
def main():
    process = psutil.Process(os.getpid())
    for i in range(0, 4000):
        rt.run()
        if i % 400 == 0:
            print('i='+str(i)+', Used Memory:', process.memory_info().rss / 1024 / 1024, 'MB')
main()

```

the start and the end is different !

I saw [Memory leak running in cpu mode on windows[tvm 0.6.0]](https://discuss.tvm.apache.org/t/memory-leak-running-in-cpu-mode-on-windows-tvm-0-6-0/5462) , the bug in openmp was fixed . I don’t konw how to fixed it !

---

<div class="post-metadata">

**Author:** ![iftaken](https://discuss.tvm.apache.org/user_avatar/discuss.tvm.apache.org/iftaken/32/2201_2.png) [@iftaken](https://discuss.tvm.apache.org/u/iftaken)\
**Post date:** [March 25, 2021, 7:45am UTC](https://discuss.tvm.apache.org/t/memory-leak-in-tvm-run-on-x64-linux/9518/2 "2021-03-25T07:45:37Z")

</div>

![image](https://discuss.tvm.apache.org/uploads/default/original/2X/d/d66b8f2a13b8f8c10b9384ff8a9f7a1747152d12.png)
