Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • VTK VTK
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 830
    • Issues 830
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 232
    • Merge requests 232
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • VTKVTK
  • VTKVTK
  • Issues
  • #18105
Closed
Open
Issue created Feb 02, 2021 by EJ Shim@EJShim

Virtual memory keeps increasing every calling vtkOctreePointLocator->GetPointsInRegion()

Below code keeps increasing virtual memory usage (tested on Windows 10) :

#include <vtkSmartPointer.h>
#include <vtkXMLPolyDataReader.h>
#include <vtkOctreePointLocator.h>
#include <vtkPolyData.h>
#include "windows.h"
#include "psapi.h"
#include <vtkIdTypeArray.h>
#include <vtkSphereSource.h>

int main(){

    
    vtkSmartPointer<vtkSphereSource> source = vtkSmartPointer<vtkSphereSource>::New();
    source->SetPhiResolution(1000);
    source->SetThetaResolution(1000);
    source->Update();


    vtkSmartPointer<vtkOctreePointLocator> octree = vtkSmartPointer<vtkOctreePointLocator>::New();
    octree->SetMaxLevel(2);
    octree->SetDataSet(source->GetOutput());
    octree->BuildLocator();


    for(int i=0 ; i<1000 ; i++){


        vtkIdTypeArray* points =  octree->GetPointsInRegion(0); // *** this line increases memory usage ***
        // points->Delete(); --> resolves this problem


        PROCESS_MEMORY_COUNTERS_EX pmc;
        GetProcessMemoryInfo(GetCurrentProcess(), (PROCESS_MEMORY_COUNTERS*)&pmc, sizeof(pmc));
        SIZE_T virtualMemUsedByMe = pmc.PrivateUsage;

        std::cout << virtualMemUsedByMe << "," << points->GetSize() << std::endl;
    }

    return 0;
}

output :

07646976,2555
107819008,2555
108806144,2555
107806720,2555
108617728,2555
109379584,2555
110297088,2555
110301184,2555
110292992,2555
110305280,2555
110292992,2555
110309376,2555
108371968,2555
108384256,2555
108261376,2555
108453888,2555
108453888,2555
110211072,2555
108482560,2555
107864064,2555
108421120,2555
108490752,2555
108679168,2555
108306432,2555
108425216,2555
108498944,2555
108494848,2555
108494848,2555
108498944,2555
108498944,2555
108314624,2555
109043712,2555
109428736,2555
109420544,2555
109420544,2555
109428736,2555
108613632,2555
.
.
.
126996480,2555
127016960,2555
127037440,2555
127057920,2555
127078400,2555
127098880,2555
127119360,2555
127139840,2555
127160320,2555
127180800,2555
127201280,2555
127221760,2555
127242240,2555
127262720,2555
127283200,2555
127303680,2555
127324160,2555
127344640,2555
127365120,2555
127385600,2555
127406080,2555
127426560,2555

In C++, I can resolve it by calling

       points->Delete();

But in Python, I cannot find ways to prevent this memory increasing problem :

import vtk
from memory_profiler import memory_usage


if __name__ == "__main__":

    source = vtk.vtkSphereSource()
    source.SetPhiResolution(1000)
    source.SetThetaResolution(1000)
    source.Update()
    polydata = source.GetOutput()


    #Build Octree
    octree = vtk.vtkOctreePointLocator()
    octree.SetMaxLevel(2)
    octree.SetDataSet(polydata)
    octree.BuildLocator()

    
    for i in range(100):


        points = octree.GetPointsInRegion(0)
        #Delete memory of points???
         
        mem_usage = memory_usage(-1, interval=1, timeout=1)
        print(mem_usage, points.GetSize())


        # points.SetNumberOfValues(0)
        # del points
        # points = None

Is there a way I can resolve it?

Assignee
Assign to
Time tracking