# Repalcement for xlnk.xlnk\_reset() in PYNQ v2.7

**URL:** <https://discuss.pynq.io/t/repalcement-for-xlnk-xlnk-reset-in-pynq-v2-7/3741>\
**Category:** Support\
**Created:** [February 25, 2022, 8:03am UTC](https://discuss.pynq.io/t/repalcement-for-xlnk-xlnk-reset-in-pynq-v2-7/3741 "2022-02-25T08:03:31Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![kai\_yao](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.pynq.io/kai_yao/32/2880_2.png) [@kai\_yao](https://discuss.pynq.io/u/kai_yao)\
**Post date:** [February 25, 2022, 8:03am UTC](https://discuss.pynq.io/t/repalcement-for-xlnk-xlnk-reset-in-pynq-v2-7/3741/1 "2022-02-25T08:03:32Z")

</div>

Hi, I’m updating my program from pynq v2.6.1 to v2.7. But I have a problem.  
I use many CMAs in my design, and I call a clean up function to release the whole CMA at startup like this:

```python
def __clean_cma(self):
    xlnk = Xlnk()
    xlnk.xlnk_reset()

```

It’s just in case the program crashes and I don’t have time to clean it up. Leaked CMA will cause allocate errors at relaunch.  
But now Xlnk is removed in v2.7, PynqBuffer.freebuffer() can release CMA but I don’t have any instance to free at startup.

Can someone kindly help me find a way to release leaked CMA?

---

<div class="post-metadata">

**Author:** ![cathalmccabe](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.pynq.io/cathalmccabe/32/3348_2.png) [@cathalmccabe](https://discuss.pynq.io/u/cathalmccabe)\
**Post date:** [March 1, 2022, 9:12am UTC](https://discuss.pynq.io/t/repalcement-for-xlnk-xlnk-reset-in-pynq-v2-7/3741/2 "2022-03-01T09:12:07Z")

</div>

You can delete the buffers you use:  
`del buffer`

Cathal

---

<div class="post-metadata">

**Author:** ![savannah](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.pynq.io/savannah/32/3182_2.png) [@savannah](https://discuss.pynq.io/u/savannah)\
**Post date:** [March 9, 2022, 8:11pm UTC](https://discuss.pynq.io/t/repalcement-for-xlnk-xlnk-reset-in-pynq-v2-7/3741/3 "2022-03-09T20:11:56Z")

</div>

Is there a way to delete all the buffers generally without calling del on each buffer used?

---

<div class="post-metadata">

**Author:** ![Annew](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.pynq.io/annew/32/2944_2.png) [@Annew](https://discuss.pynq.io/u/Annew)\
**Post date:** [March 21, 2022, 10:43am UTC](https://discuss.pynq.io/t/repalcement-for-xlnk-xlnk-reset-in-pynq-v2-7/3741/4 "2022-03-21T10:43:45Z")

</div>

I meet the same problem with you.  
Have you sloved it?

---

<div class="post-metadata">

**Author:** ![marioruiz](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.pynq.io/marioruiz/32/2177_2.png) [@marioruiz](https://discuss.pynq.io/u/marioruiz)\
**Post date:** [March 21, 2022, 2:35pm UTC](https://discuss.pynq.io/t/repalcement-for-xlnk-xlnk-reset-in-pynq-v2-7/3741/5 "2022-03-21T14:35:58Z")

</div>

Hi,

There is no direct replacement for this since pynq 2.7.

You may have to restructure your code to `del` the buffer after finishing your application, this is the pythonic way.

Mario

---

<div class="post-metadata">

**Author:** ![Annew](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.pynq.io/annew/32/2944_2.png) [@Annew](https://discuss.pynq.io/u/Annew)\
**Post date:** [March 22, 2022, 3:26am UTC](https://discuss.pynq.io/t/repalcement-for-xlnk-xlnk-reset-in-pynq-v2-7/3741/6 "2022-03-22T03:26:51Z")

</div>

(post deleted by author)

---

<div class="post-metadata">

**Author:** ![Annew](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.pynq.io/annew/32/2944_2.png) [@Annew](https://discuss.pynq.io/u/Annew)\
**Post date:** [March 22, 2022, 3:27am UTC](https://discuss.pynq.io/t/repalcement-for-xlnk-xlnk-reset-in-pynq-v2-7/3741/7 "2022-03-22T03:27:44Z")

</div>

Thank you very much.

But sorry I haven’t found a python function to free buffer. Could you give me an example?

My memory reduced even after `del buffer` .

I don’t know why and now I have to use the Linux command `echo 1 > /proc/sys/vm/drop_caches` on the terminal to free buffer , but it’s not useful all the time.

I have no idea what `allocate` have done to my ram.It becomes confusing when python plus fpga.

---

<div class="post-metadata">

**Author:** ![Annew](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.pynq.io/annew/32/2944_2.png) [@Annew](https://discuss.pynq.io/u/Annew)\
**Post date:** [March 22, 2022, 7:04am UTC](https://discuss.pynq.io/t/repalcement-for-xlnk-xlnk-reset-in-pynq-v2-7/3741/8 "2022-03-22T07:04:49Z")

</div>

Hi  
Thank you ! I solved it !! `del` needs to company with ` gc.collect()`

```auto
import gc

params_w = np.fromfile("yolo.bin", dtype=np.uint32) 
np.copyto(weight_buffer, params_w)

del params_w
gc.collect()

```

---

<div class="post-metadata">

**Author:** ![Annew](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.pynq.io/annew/32/2944_2.png) [@Annew](https://discuss.pynq.io/u/Annew)\
**Post date:** [March 26, 2022, 3:18am UTC](https://discuss.pynq.io/t/repalcement-for-xlnk-xlnk-reset-in-pynq-v2-7/3741/9 "2022-03-26T03:18:58Z")

</div>

The complete code is as follows

```auto
inport allocate # replace Xlnk
import gc

weight_buffer = allocate(shape=(25470896,), dtype=np.uint32) # allocate 100M memory
params_w = np.fromfile("yolo.bin", dtype=np.uint32) # read the file
np.copyto(weight_buffer, params_w) # load the file to the 100M memory

del params_w # will not be used again, so delete it to free memory
gc.collect()

```
