# Reset Session programatically in python macro

**URL:** https://discourse.paraview.org/t/reset-session-programatically-in-python-macro/9218
**Category:** Development
**Tags:** python
**Created:** [March 18, 2022, 8:30am UTC](https://discourse.paraview.org/t/reset-session-programatically-in-python-macro/9218 "2022-03-18T08:30:18Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Gianmarco](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/g/13edae/32.png) [@Gianmarco](https://discourse.paraview.org/u/Gianmarco)
#### Post date: [March 18, 2022, 8:30am UTC](https://discourse.paraview.org/t/reset-session-programatically-in-python-macro/9218/1 "2022-03-18T08:30:18Z")

</div>

Hello,

I’m running a macro with loops that use a lot of memory. What I’d like to do is to clean the memory between loops. However if I add a

ResetSession()

in the macro, Paraview crashes.  
I tried something like

for x in GetSources().values():  
Delete(x[0])

but it doesn’t seem to clean the memory.

Is there a solution to this problem?

Thanks,  
Gianmarco

---

<div class="post-metadata">

### Author: ![cory.quammen](https://discourse.paraview.org/user_avatar/discourse.paraview.org/cory.quammen/32/11193_2.png) [@cory.quammen](https://discourse.paraview.org/u/cory.quammen)
#### Post date: [March 18, 2022, 1:30pm UTC](https://discourse.paraview.org/t/reset-session-programatically-in-python-macro/9218/2 "2022-03-18T13:30:21Z")

</div>

This is a known issue, unfortunately.

[https://gitlab.kitware.com/paraview/paraview/-/issues/18261](https://gitlab.kitware.com/paraview/paraview/-/issues/18261)

A work around is to use

```auto
Disconnect()
Connect()

```

---

<div class="post-metadata">

### Author: ![Gianmarco](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/g/13edae/32.png) [@Gianmarco](https://discourse.paraview.org/u/Gianmarco)
#### Post date: [March 18, 2022, 3:00pm UTC](https://discourse.paraview.org/t/reset-session-programatically-in-python-macro/9218/3 "2022-03-18T15:00:42Z")

</div>

Thank you for your reply Cory.  
It seems, however, that also the Disconnect() / Connect() method crashes if used in a macro.  
Isn’t there any other way to free memory while in use? I could also accept to close and reopen Paraview, as long as it is automated.

Thanks

---

<div class="post-metadata">

### Author: ![wascott](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/w/8e8cbc/32.png) [@wascott](https://discourse.paraview.org/u/wascott)
#### Post date: [March 18, 2022, 3:50pm UTC](https://discourse.paraview.org/t/reset-session-programatically-in-python-macro/9218/4 "2022-03-18T15:50:36Z")

</div>

I just marked this as a showstopper for the 5.11 release. (Reference the bug Cory pointed at.) I hate crashes, and it looks like there isn’t a workaround. Thanks Gianmarco for reporting.
