# ResetSession not clearing memory

**URL:** https://discourse.paraview.org/t/resetsession-not-clearing-memory/15975
**Category:** ParaView Support
**Tags:** python
**Created:** [January 13, 2025, 5:48pm UTC](https://discourse.paraview.org/t/resetsession-not-clearing-memory/15975 "2025-01-13T17:48:31Z")
**Posts on this page:** 1
**Showing post:** 5

<div class="post-metadata">

### Author: ![ihelt](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/i/5e9695/32.png) [@ihelt](https://discourse.paraview.org/u/ihelt)
#### Post date: [January 16, 2025, 2:19pm UTC](https://discourse.paraview.org/t/resetsession-not-clearing-memory/15975/5 "2025-01-16T14:19:09Z")

</div>

I had previously opened an issue here ([Paraview ResetSession causing crashes - #3 by ihelt](https://discourse.paraview.org/t/paraview-resetsession-causing-crashes/15751/3)) about ResetSession() causing a crash which had a similar minimally working example (in case this looks familiar), but the code below creates a new layout, which was a remedy suggested in issue 22831 ([https://gitlab.kitware.com/paraview/paraview/-/issues/22831](https://gitlab.kitware.com/paraview/paraview/-/issues/22831)).

```auto
from paraview.simple import *
import os

class pv:
    def __init__ (self,casename):
        print('Initializing...')
        self.enReader = EnSightReader(registrationName='case1', CaseFileName=casename)

        # Create layout: Remedy to ResetSession crashing (Paraview issue 22831)
        layout = CreateLayout()
        self.renderView = GetActiveViewOrCreate('RenderView')
        AssignViewToLayout(view=self.renderView, layout=layout)

    def __del__ (self):
        print('deleting...')
        Delete(self.enReader)
        ResetSession()

    def makeBlock(self):
        print('Making block...')
        self.extractBlock = ExtractBlock(registrationName='block', Input=self.enReader)
        self.extractBlockDisplay = Show(self.extractBlock, self.renderView, 'UnstructuredGridRepresentation')
        self.extractBlock.Selectors = ['booster']
        
    def makePicture(self,picName):
        pic_path = './'+picName+'.png'
        print('Saving '+picName+'...')
        
        layout = GetLayout()
        layout.SetSize(1400,200)
        if os.path.exists(pic_path):
            os.remove(pic_path)
        SaveScreenshot(pic_path, self.renderView, ImageResolution=[1400, 200], OverrideColorPalette='BlackBackground')
        

def main():

    # NOTE: "error: exception occurred: Subprocess killed" is a result of all memory being used by CPU
    casename1 = /path/to/file.case'

    i = 1
    while i < 10:
        print('-----------------------------------')
        pvi = pv(casename1)
        pvi.makeBlock()
        pvi.makePicture('pic{0:d}'.format(i))
        pvi. __del__ ()
        del pvi
        print('pv{0:d} done'.format(i))
        i = i+1

    print('done')

if __name__ == ' __main__':
    main()

```

Executing this code gives me the following output:

```auto
user:> pvpython --mesa replicateCrash.py
-----------------------------------
Initializing...
VisRTX 0.1.6, using devices:
 0: Quadro P2000 (Total: 5.3 GB, Available: 5.1 GB)
Making block...
Saving pic1...
deleting...
deleting...
pv1 done
-----------------------------------
Initializing...
Making block...
Saving pic2...
deleting...
deleting...
pv2 done
-----------------------------------
Initializing...
Making block...
Saving pic3...
deleting...
deleting...
pv3 done
-----------------------------------
Initializing...
Making block...
error: exception occurred: Subprocess killed

```

where the crash coincides with my memory usage being completely full.

---

_[View the full topic](https://discourse.paraview.org/t/resetsession-not-clearing-memory/15975)._
