Remove results don't free memory

Hi,
I think it’s a bug : when I delete FEMResults object from FreeCAD tree, the memory used by the soft doesn’t reduce. So I have to close the app between each calculus…

Can reproduce this mem leak :frowning:

tested with:OS: Windows 10
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.18.13826 (Git)
Build type: Release
Branch: master
Hash: 3b02ff2a9481f0883063c7e24c312978ef0ce642
Python version: 2.7.14
Qt version: 4.8.7
Coin version: 4.0.0a
OCC version: 7.2.0
Locale: German/Germany (de_DE)

to reproduce …

  • start FreeCAD

  • load 3D FEM example

  • double click analysis

  • Menu Results → purge results

  • double click on the mesh

  • change max size to 100 → ok → the mesh has ca 40000 volumens

  • check memory of FreeCAD, for me on Windows 262 MB

  • run analysis → after loading the results FreeCAD needs 453 MB

  • Menue Results → purge results → still 427 MB

  • run analysis → after loading the results FreeCAD needs 546 MB

  • Menue Results → purge results → still 543 MB

  • run analysis → after loading the results FreeCAD needs 668 MB

  • Menue Results → purge results → still 662 MB

  • Memory goes up on every run

  • do not purge results

  • save the file

  • close FreeCAD

  • load the file

  • FreeCAD needs 331 MB

What happens on result purge …

command:
https://github.com/FreeCAD/FreeCAD/blob/bf03c7bcb11205885999b23874e88af7998ffd92/src/Mod/Fem/femcommands/commands.py#L593-L594

method:
https://github.com/FreeCAD/FreeCAD/blob/bf03c7bcb11205885999b23874e88af7998ffd92/src/Mod/Fem/femresult/resulttools.py#L35-L41

I don’t think the problem is in purging the result objects. I rather assume the memory is leaking in the Analysis function when running ccx. If you once clicked on the button to write the .inp file then press several times the button to run ccx then you can see in the task manager that quite a big block of memory is allocated but never freed.

attached link to a bigger FreeCAD result file.

  • download document
  • open in FreeCAD
  • watch memory
  • delete result object and result mesh in TreeView
  • it seams no memory is released … ?

Is it what you guys think it is a bug _UR and flachyjoe ?


https://pro.woelkli.com/s/gkqZNsHjZTMnMk7

3D example file from start page:

mem usage FreeCAD.exe.png

Hello!

When i doubleclick the resulst of this test file and close the result tab, the RAM for FreeCAD gets bigger. The from 0.8GB to 1.3GB in 10 times.

test done with:

OS: Debian GNU/Linux 9.4 (stretch)
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.18.13885 (Git)
Build type: Release
Branch: master
Hash: 211a24507ca636678176f1d6b4c0ce41e02ad7c8
Python version: 2.7.13
Qt version: 4.8.7
Coin version: 4.0.0a
OCC version: 7.3.0
Locale: English/UnitedStates (en_US)

OpenCloseResults10times.png
Load_TEST_FirstTime.png
OpenFreeCAD.png
Greetings
user1234

Of course not if undo/redo is enabled.

But if you remove the mesh and undo it you will see that further 300MB are allocated. And to show that this has nothing to do with the result object delete it and save the file. Then open the file in a new FreeCAD instance and delete the mesh and undo it. It again allocates 300MB.

Hi !

It’s obvious now. Does exist a way to disable undo for one operation only ?
On another point of view, is it possible to undelete by re-read the files and so the memory can be released when object is deleted ?

mem usage Undo OFF.png
3 full cycles:

  • meshing (netgen)
  • solving
  • delete mesh and result

Edit->Preferences->General->Document->Using Undo: Unchecked

It’s obvious now. Does exist a way to disable undo for one operation only ?

No because this would make the whole undo/redo system unusable. But this anyway isn’t the part that causes the leak.

I have detected two functions that leaks memory:
DriverUNV_W_SMDS_Mesh::Perform() – around 100MB for each call in debug mode
ViewProviderFEMMeshBuilder::createMesh – around 700MB for each call in debug mode

One major memory leak is in the methods SMDS_MeshNode::X,Y,Z. Internally they invoke SMDS_MeshNode::getCoord which allocates memory on the heap for three doubles but the calling instances don’t free it.

Edit: It appeared that this leak is responsible for the leaks in DriverUNV_W_SMDS_Mesh::Perform() and ViewProviderFEMMeshBuilder::createMesh and fixing it solves all the mentioned leaks.

fc47266829

I have temporary removed the ignore flag from the 3rdParty in Coverity, sure enough there are a lot of issues reported in salomesmesh code, a lot of them also in the High impact category…

I am also working on a new Coverity build…

looks a little bit better now.
mem usage.png
3 full cycles:

  • meshing (netgen)
  • solving
  • delete mesh and result

Edit->Preferences->General->Document->Using Undo: Unchecked

tested with:OS: Windows 10
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.18.13892 (Git)
Build type: Release
Branch: master
Hash: 23f58f1afc710c6189ac44414c8696e8e838535c
Python version: 2.7.14
Qt version: 4.8.7
Coin version: 4.0.0a
OCC version: 7.2.0
Locale: German/Germany (de_DE)

only for comparison:

paraview.png
3 full cycles:

  • loading results (from previous post)
  • delete results

Undo enabled (don’t know if it could be disabled anyway)

tested with:
paraview 5.5.0 x64