Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pythreejs.BufferGeometry] Memory continues to grow #387

Open
spencergotowork opened this issue Sep 2, 2022 · 6 comments
Open

[pythreejs.BufferGeometry] Memory continues to grow #387

spencergotowork opened this issue Sep 2, 2022 · 6 comments

Comments

@spencergotowork
Copy link

Does the memory of this part of BufferGeometry automatically reclaim? Or do I need a manual recycling method? I called this in a function, but left the function to show that memory kept growing. like that:

截图 2022-09-02 14-37-13

@spencergotowork
Copy link
Author

spencergotowork commented Sep 13, 2022

import gc
for i in range(10000):
    g3 = LineSegmentsGeometry(
        positions=[
            [[0, 0, 0], [1, 1, 1]],
            [[2, 2, 2], [4, 4, 4]]
        ],
        colors=[
            [[1, 0, 0], [1, 0, 0]],
            [[0, 1, 0], [0, 0, 1]]
        ],
    )
    m3 = LineMaterial(linewidth=10, vertexColors='VertexColors')
    line3 = LineSegments2(g3, m3)

    del g3, m3, line3
    
    if (i%100) == 0:
        gc.collect()

Take this code, memory will keep going up. Is there a way to clear the memory of BufferAttribute or LineSegmentsGeometry.
I use scene.add and scene.remove to animate the demo, each frame has a different number of objects, so I can't simply modify geometry. attributes to get the result

@nvaytet
Copy link

nvaytet commented Oct 10, 2022

Were you running this in Jupyter? Could this have to do with the fact that ipython by default holds on to references of the cell outputs, and thus the memory does not get freed? (see https://ipython.readthedocs.io/en/stable/interactive/reference.html?highlight=previous#output-caching-system)

Although your code doesn't seem to be producing any output...

@spencergotowork
Copy link
Author

Were you running this in Jupyter? Could this have to do with the fact that ipython by default holds on to references of the cell outputs, and thus the memory does not get freed? (see https://ipython.readthedocs.io/en/stable/interactive/reference.html?highlight=previous#output-caching-system)

Although your code doesn't seem to be producing any output...

Thank you for your reply. I have been running on jupyter lab and can see that memory is growing gradually.

@nvaytet
Copy link

nvaytet commented Oct 10, 2022

Can you try running the same code in a python script to see if the memory also grows there?

@vidartf
Copy link
Member

vidartf commented Oct 12, 2022

This is probably related to this general ipywidgets issue: jupyter-widgets/ipywidgets#1345

@vidartf
Copy link
Member

vidartf commented Oct 12, 2022

i.e. you probably need to call .close() on the widget before calling del to ensure it gets cleaned up properly. As @nvaytet points out, any widget included in an output can also possibly be kept a reference to via ipython output caching. But at least for your simplest example above, .close() should be the needed piece.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants