[Solved] memory leak in distToShape

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
User avatar
looo
Veteran
Posts: 3941
Joined: Mon Nov 11, 2013 5:29 pm

[Solved] memory leak in distToShape

Post by looo »

Encountered this when using this function for a least-square calibration.

To reproduce:

Code: Select all

import Part as part
a = part.Vertex(0,0,0)
b = part.Vertex(1,1,1)
for _ in range(int(3e6)):
    dist = a.distToShape(b)
    del dist
Bildschirmfoto von 2019-12-12 10-18-00.png
Bildschirmfoto von 2019-12-12 10-18-00.png (19.88 KiB) Viewed 1244 times

Code: Select all

OS: Ubuntu 18.04.3 LTS (ubuntu:GNOME/ubuntu)
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.19.18846 (Git)
Build type: Release
Branch: master
Hash: ceeb776fff25c679752571d5d8e6c4c8b1fd9008
Python version: 3.7.3
Qt version: 5.12.5
Coin version: 4.0.0a
OCC version: 7.3.0
Locale: German/Germany (de_DE)

Last edited by Kunda1 on Tue Dec 17, 2019 1:18 pm, edited 1 time in total.
Reason: Added [Solved] to thread title
openBrain
Veteran
Posts: 9041
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: memory leak in distToShape

Post by openBrain »

Confirmed with :

Code: Select all

OS: Windows 7 SP 1 (6.1)
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.19.18934 (Git)
Build type: Release
Branch: master
Hash: 540aeada3a5d1e460cb30671af4bb9a747def942
Python version: 3.6.8
Qt version: 5.12.1
Coin version: 4.0.0a
OCC version: 7.3.0
Locale: French/France (fr_FR)
User avatar
DeepSOIC
Veteran
Posts: 7896
Joined: Fri Aug 29, 2014 12:45 am
Location: used to be Saint-Petersburg, Russia

Re: memory leak in distToShape

Post by DeepSOIC »

Code: Select all

>>> a = Part.Vertex(0,0,0)
>>> b = Part.Vertex(1,1,1)
>>> dist = a.distToShape(b)
>>> import sys
>>> sys.getrefcount(dist)
2
>>> sys.getrefcount(dist[0])
2
>>> sys.getrefcount(dist[1])
3
>>> sys.getrefcount(dist[2])
3
>>> sys.getrefcount(dist[1][0])
3
>>> sys.getrefcount(dist[2][0])
3
where refcount is 3, a reference was leaked.
User avatar
DeepSOIC
Veteran
Posts: 7896
Joined: Fri Aug 29, 2014 12:45 am
Location: used to be Saint-Petersburg, Russia

Re: memory leak in distToShape

Post by DeepSOIC »

I'm busy fixing it...

EDIT: it's going to take a while longer than expected, as updating the source somehow nuked my build setup, I'm recovering it.
User avatar
DeepSOIC
Veteran
Posts: 7896
Joined: Fri Aug 29, 2014 12:45 am
Location: used to be Saint-Petersburg, Russia

Re: memory leak in distToShape

Post by DeepSOIC »

User avatar
DeepSOIC
Veteran
Posts: 7896
Joined: Fri Aug 29, 2014 12:45 am
Location: used to be Saint-Petersburg, Russia

Re: memory leak in distToShape

Post by DeepSOIC »

PR canceled, because there are more problems with refcounting. Now the test crashes FreeCAD as a result of deallocating None.
User avatar
DeepSOIC
Veteran
Posts: 7896
Joined: Fri Aug 29, 2014 12:45 am
Location: used to be Saint-Petersburg, Russia

Re: memory leak in distToShape

Post by DeepSOIC »

User avatar
looo
Veteran
Posts: 3941
Joined: Mon Nov 11, 2013 5:29 pm

Re: memory leak in distToShape

Post by looo »

Thanks @DeepSOIC. I cherry-picked the PR but updated libraries previously and now my local build is not working anymore. I will trigger ci's as soon as it is merged (the lazy way).
wmayer
Founder
Posts: 20298
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: memory leak in distToShape

Post by wmayer »

It's merged now.
User avatar
Kunda1
Veteran
Posts: 13434
Joined: Thu Jan 05, 2017 9:03 pm

Re: [Solved] memory leak in distToShape

Post by Kunda1 »

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
Post Reply