More Weird Behavior from the Draft WB: Memory Leak?
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Be nice to others! Respect the FreeCAD code of conduct!
Re: More Weird Behavior from the Draft WB: Memory Leak?
If i repeat the rectangle test as described earlier. I can confirm the amount of memory increase involved is nowhere near the levels as seen before.
Re: More Weird Behavior from the Draft WB: Memory Leak?
I can confirm that the memory usage increases by ~30MB but the conclusion is wrong that it's caused by pivy. You achieve the same effect when you simply write:yorik wrote: ↑Wed Feb 21, 2018 4:05 pm I was able to narrow down the memory leak further, it seems to happen inside pivy. For example, this creates a ~30Mb memory increase (takes a couple of minutes to complete):
Can someone else can test the code snippet above and confirm the memory being eaten?Code: Select all
from pivy import coin c = coin.SoCoordinate3() pts = [[0.0,0.0,0.0],[1.0,1.0,1.0]] for i in range(1000000): c.point.setValues(pts)
Code: Select all
r=range(1000000)
Code: Select all
del r # frees ~10MB
import gc
gc.collect() # frees the remaining ~20MB
Code: Select all
import gc
from pivy import coin
c = coin.SoCoordinate3()
pts = [[0.0,0.0,0.0],[1.0,1.0,1.0]]
for i in range(1000000):
c.point.setValues(pts)
gc.collect()
Code: Select all
from pivy import coin
c = coin.SoCoordinate3()
pts = [[0.0,0.0,0.0],[1.0,1.0,1.0]]
i=0
while i<1000000:
c.point.setValues(pts)
i=i+1
Code: Select all
SbVec3f pts[2] = {SbVec3f(0.0,0.0,0.0),SbVec3f(1.0,1.0,1.0)};
SoCoordinate3* c = new SoCoordinate3();
for (int i=0;i<1000000;i++)
c->point.setValues(0,2,pts);
Re: More Weird Behavior from the Draft WB: Memory Leak?
Wow thanks... that's a real programming lesson!
I thought that when you existed a function, all variables created inside would automatically be deleted by the automatic garbage collection that I always heard python had... And in our case, the problem is not that setValues() runs inside a big loop, but rather that it is called on every mouse move... So in theory the function that contains the setValues() statement is exited each time... I still don't understand...
But it occurs to me now, that actually the whole draft snap queue is triggered on every mouse move, and that you can therefore have several concurrent queues running... That sounds like extremely bad programming I'll experiment letting it run only one concurrent at a time.
I thought that when you existed a function, all variables created inside would automatically be deleted by the automatic garbage collection that I always heard python had... And in our case, the problem is not that setValues() runs inside a big loop, but rather that it is called on every mouse move... So in theory the function that contains the setValues() statement is exited each time... I still don't understand...
But it occurs to me now, that actually the whole draft snap queue is triggered on every mouse move, and that you can therefore have several concurrent queues running... That sounds like extremely bad programming I'll experiment letting it run only one concurrent at a time.
Re: More Weird Behavior from the Draft WB: Memory Leak?
Ok I committed a small change that optimizes snapping a lot, but the memory leak is still there... Don't know where it comes from if not from pivy... I'll investigate more then
Re: More Weird Behavior from the Draft WB: Memory Leak?
One remark about the speed issue. I first thought that it could be caused by the SWIG generated code which does quite a lot of type checking and conversions and so on. But when changing the code to:
then it only takes a couple of seconds to execute. And when changing the original example to
then it also finishes after a couple of seconds. So, the conclusion is that accessing the field of an Inventor node in pivy is very expensive.
Code: Select all
from pivy import coin
point = coin.SoMFVec3f()
pts = [[0.0,0.0,0.0],[1.0,1.0,1.0]]
i=0
while i<1000000:
point.setValues(pts)
i=i+1
Code: Select all
from pivy import coin
c = coin.SoCoordinate3()
point = c.point
pts = [[0.0,0.0,0.0],[1.0,1.0,1.0]]
i=0
while i<1000000:
point.setValues(pts)
i=i+1
Re: More Weird Behavior from the Draft WB: Memory Leak?
Aha that's a very good find... Too much to touch in all Draft to do that now, so close to the release I think, but I'll do that right after. Could give a massive speed gain...
Re: More Weird Behavior from the Draft WB: Memory Leak?
Is there a logical conclusion to issue #3340 then?
Alone you go faster. Together we go farther
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
'good first issues' | Open TODOs and FIXMEs | How to Help FreeCAD | How to report Bugs
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
'good first issues' | Open TODOs and FIXMEs | How to Help FreeCAD | How to report Bugs
Re: More Weird Behavior from the Draft WB: Memory Leak?
Not really, but I'll test that again