I'm working on a workbench doing some animations and I found a memory leak while modifying Placement objects. I managed to reproduce the issue with a macro.
I'm moving a part from the part workbench back and forth along the x axis for 5 minutes with a lot of modifications of the Placement object of the part. I use way to much translations to make the problem more obvious. Here is the macro:
Code: Select all
import time
def SimulateTranslationAxis(elementName, direction, positionFrom, positionTo, duration, returnInPosition):
element = FreeCAD.ActiveDocument.getObject(elementName)
FPS = 30
length = abs(positionTo - positionFrom)
stepCount = int(duration * FPS)
stepLength = length / stepCount
directionVector = FreeCAD.Vector(direction[0], direction[1], direction[2]).normalize()
target = element.Placement.copy()
target.move(directionVector * (positionTo - positionFrom))
if positionFrom > positionTo:
directionVector *= -1
stepMove = directionVector * stepLength / 100
for _ in range(stepCount):
start = time.perf_counter()
for _ in range(100):
base = element.Placement.Base
element.Placement.Base.x = base.x + stepMove.x
element.Placement.Base.y = base.y + stepMove.y
element.Placement.Base.z = base.z + stepMove.z
Gui.updateGui()
sl = 1.0 / FPS - (time.perf_counter() - start)
time.sleep(sl if sl > 0.0 else 0.0)
element.Placement = target
startTime = time.perf_counter()
while time.perf_counter() - startTime < 300:
SimulateTranslationAxis("Box", (1, 0, 0), 0, 150, 1, False)
time.sleep(1.1)
SimulateTranslationAxis("Box", (1, 0, 0), 150, 0, 1, False)
time.sleep(1.1)
SimulateTranslationAxis("Box", (-1, 0, 0), 0, 150, 1, False)
time.sleep(1.1)
SimulateTranslationAxis("Box", (-1, 0, 0), 150, 0, 1, False)
time.sleep(1.1)
Except for the useless "for _ in range(100)" loop in this macro is there anything wrong that can produce this result? I tried different ways of moving the part (Placement.move(), Placement.multiply(), creating a new Placement and assigning it,...) but nothing I tried works.
I tried with version 0.18, 0.19 and 0.20 of FreeCAD:
Code: Select all
OS: Windows 10 Version 1903
Word size of FreeCAD: 64-bit
Version: 0.20.29177 (Git)
Build type: Release
Branch: releases/FreeCAD-0-20
Hash: 68e337670e227889217652ddac593c93b5e8dc94
Python 3.8.10, Qt 5.15.2, Coin 4.0.1, Vtk 8.2.0, OCC 7.6.2
Locale: French/Switzerland (fr_CH)
Installed mods:
* Assembly4 0.11.10
* MeshRemodel 1.8918.0
* Render 2022.1.0