paraview python script : Delete(renderView1) does not free memory

老子叫甜甜 提交于 2019-12-24 05:21:04

问题


I am trying to load multiple state files by running a python script with python shell. The script is the following

#### import the simple module from the paraview
from paraview.simple import *

for time in range(0,200):
        renderView1 = GetActiveViewOrCreate('RenderView')

        # destroy renderView1
        Delete(renderView1)
        del renderView1

        filename = 'filepath/filename-%s.pvsm' % time
        servermanager.LoadState(filename)
        renderView=SetActiveView(GetRenderView())
        Render()
        # get layout
        viewLayout = GetLayout()

        # save screenshot
        SaveScreenshot('filepath/filename-%s.png' % time, layout=viewLayout, magnification=3, quality=100)

I was monitoring the memory used by machine, after some time steps the memory used by the machine is whole RAM. Can anybody tell me what I am doing wrong here.

I appreciate your time and support.

Thanks Raj


回答1:


Python is garbage-collected, which means that there are no guarantees that an object is actually removed from memory when you do 'del someBigObject'. In fact, doing 'del someObject' is not only pointless, it's considered bad style.

del only removes the binding between that identifier and the object. Thus del doesn't actually result in the object being deleted from memory.

See this for full details: https://www.quora.com/Why-doesnt-Python-release-the-memory-when-I-delete-a-large-object




回答2:


As suggested by Utkarsh the following script solved my problem. For details see this answer.

--------------------------------------------------------------------------------
from paraview.simple import *

def ResetSession():
    pxm = servermanager.ProxyManager()
    pxm.UnRegisterProxies()
    del pxm
    Disconnect()
    Connect()

for i in range(0, 10):
    ResetSession()
    servermanager.LoadState("/tmp/sample.pvsm")
    renderView=SetActiveView(GetRenderView())
    Render()
--------------------------------------------------------------------------------


来源:https://stackoverflow.com/questions/31423347/paraview-python-script-deleterenderview1-does-not-free-memory

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!