I have a whole lot of variables with large meshes in them, in this is causing my computer to run out of memory. But I’m using the meshes one at a time, so I could clear the variable of the mesh data, freeing up memory, I think… I’ve been trying to do this by using mesh.dispose, but that doesn’t seem to do the trick. Any suggestions?
Still trying to figure this one out. I’m taking Menno’s suggestion and reusing the same variable to store the meshes. I’ve made the mesh variable a shared variable in a class. If I understand correctly, the shared variable is just one variable regardless of how many instances of the class are created, and so when I populate the shared variable with a new mesh, the old mesh gets cleared from memory. Does this make sense?
But even after trying this, I’m still finding I’m running out of memory. I could make a lot of other variables similarly shared, but before I undertake that work, I’m hoping someone can tell me that my reasoning is sound.
Or perhaps there is something else I should be doing to avoid the gradual creap in memory usage as my plugin continues to run a rather long command. Below is a screenshot of the heap, if that’s any help, or perhaps there is a better way to diagnose memory issues?
Any help would be greatly appreciated,
Thanks,
Sam
I’ve done some more digging, and I think what’s causing the problem is that I am deleting objects and then adding transformed versions of them back to the document. I’m doing this in loops within loops within loops, so a lot of itterations all in a single command. And every time I delete and add an object back, memory usage creeps upwards. Please see the code below to see what I mean. Any suggestions on how I can work around this issue will still executing it in a single command?
Thanks,
Sam
Dim Sphere = New Sphere(Point3d.Origin, 10).ToBrep
Dim SphereID = doc.Objects.AddBrep(Sphere)
For i = 0 To 9999
Dim xform = Transform.Translation(New Vector3d(0, 0, 0.1))
Sphere.Transform(xform)
doc.Objects.Delete(SphereID, True)
SphereID = doc.Objects.AddBrep(Sphere)
doc.Views.Redraw()
Next
My example was over simplified… I’m actually modifying the object then adding it back, sometimes using a spacemorph. Can that be done in a display conduit? If not, thoughts on how to deal with the memory issue?
I’m batching simulations, but you’re questions helped me realize that I don’t need to provide visualization for long batches, so I’ll just not add and delete geometry incessantly. It’s only single simulations where visualization is important. I’ll try to fix it up. Depending on how it goes, I might try conduits at some point for single simulations where visualization is important.
I’m taking Menno’s suggestion and reusing the same variable
Please note the difference between object and variable. If you assign a new mesh to the old variable, you are not reusing the object. What I meant is that you have one mesh object, whose vertices and faces you keep changing. Seeing your other posts however, I wonder if this is really the issue.
The issue turned out to be adding and removing objects from the document many times. I’ve eliminated this for big batches and runs without the memory issues.