# experiencing memory leaks on python, trying to understand why...

**URL:** <https://discourse.paraview.org/t/experiencing-memory-leaks-on-python-trying-to-understand-why/17817>\
**Category:** ParaView Support\
**Created:** [November 17, 2026, 10:31am UTC](https://discourse.paraview.org/t/experiencing-memory-leaks-on-python-trying-to-understand-why/17817 "2026-11-17T10:31:18Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![otaolafr](https://discourse.paraview.org/user_avatar/discourse.paraview.org/otaolafr/32/3595_2.png) [@otaolafr](https://discourse.paraview.org/u/otaolafr)\
**Post date:** [November 17, 2026, 10:31am UTC](https://discourse.paraview.org/t/experiencing-memory-leaks-on-python-trying-to-understand-why/17817/1 "2026-11-17T10:31:18Z")

</div>

Hello,  
i am experiencing memory leaks for if i use to call this the function extractSingleRandomCell() thought a loop. the function itself it extracts a single element of a dataset. currently using it to extract a voxel from a image data, where there are ghost cells therefore i need to extract the first cell that is not ghost, so basically the output of it is ‘just a single box’.

in my loop i extracting this box and fetching the data points, saving them and then deleting the ‘box’ by using:

```auto
Delete(box)
del box
gc.collect()

```

even though i am doing this so at the end of each iteration of the loop the ram it just keep increasing.  
the two ‘culprit’ functions that i am using that is causing this, (I am sure that it is coming from this as if i simply create a box with the Box filter the memory leak is not happening)

```auto
def extractSingleRandomCell(filter):
    from paraview import servermanager
    if filter.GetDataInformation().GetDataSetTypeAsString()=='vtkImageData':
        data=servermanager.Fetch(filter)
        cellsGhosts = data.GetCellData().GetArray("vtkGhostType")
        value = next(i for i in range(cellsGhosts.GetNumberOfTuples()) if cellsGhosts.GetValue(i) == 0)
        field='CellIds'
    else:
        value=0
        field='id'
    cell=extractSelectionByListOfValues(filter=filter, fieldName=field, listOfValues=value, singleValueComparation='==' ,cellOrPoints='CELL',complementary=False, registrationName='')
    return cell

def extractSelectionByListOfValues(filter, fieldName='', listOfValues=[], singleValueComparation='==' ,cellOrPoints='CELL',complementary=False, registrationName=''):
    """
    Extract cells or points whose field 'fieldName' matches one of listOfValues
    """
    if 'CELL' in cellOrPoints.upper():
        FieldType = paraview.vtk.vtkDataObject.CELL
    elif 'POINT' in cellOrPoints.upper():
        FieldType = paraview.vtk.vtkDataObject.POINT
    if isinstance(listOfValues,list) and len(listOfValues)==1:
        listOfValues=listOfValues[0]        
    if isinstance(listOfValues,list):
        if not isinstance(listOfValues,list):
            try:
                listOfValues=listOfValues.tolist()
            except:
                print(f'listOfValues given is not a vtkArray nor npArray nor list')
                return
        vMajor,vMinor=GetParaViewVersion().major,GetParaViewVersion().minor
        if vMajor<=6 and vMinor<1:
            selection = CreateSelection('SelectionQuerySource','valueSelection',ElementType=FieldType,QueryString=f'in1d({fieldName}, {listOfValues})',InsideOut=complementary)
        else:
            selection = CreateSelection('SelectionQuerySource','valueSelection',ElementType=FieldType,QueryString=f'isin({fieldName}, {listOfValues})',InsideOut=complementary)
    else:
        selection = CreateSelection('SelectionQuerySource','valueSelection',ElementType=FieldType,QueryString=f'({fieldName} {singleValueComparation} {listOfValues})',InsideOut=complementary)
    extracted = ExtractSelection(Input=filter,Selection=selection,registrationName=registrationName)
    return extracted #<- this will be the box that i will after delete.

```

thanks in advance.
