Memory leak in simulation
Description
Repeated simulations executed in a long-running kicad process result in unexpectedly high memory consumption. Memory isn't freed after the simulation window is closed, thus it is a memory leak.
Steps to reproduce
- Start kicad, open or create a schematic (the more parts, the better), create a text element with spice simulation instructions (e.g., ".tran 1n 1m 0 0 uic", but I don't think the actual values matter); remember the size of the kicad process in memory
- Open the simulation window
- Run simulation, stop simulation (within 1-2 sec, to reproduce what I do)
- Close the simulation window, click "Discard changes"
- Open the simulation window again
- Run simulation and stop simulation (within 1-2 sec) 10 times
- Close the simulation window again; compare the size of kicad process in memory with that from step 1.
After following the above steps, in my case the kicad process grows from about 380MB initially to about 4GB before step 7 and rolls back to 3.7GB after step 7. Repeating the steps again cause the process to grow for another 4GB.
In practice I often notice, when using KiCad, that my system is about to run out of memory, and when I run top
, I usually find that the kicad process occupies well above 20GB of memory. The only way to have it freed is to restart KiCad. Closing only eeschema has no effect -- main window must be closed as well.
I am attaching a project with a (synthetic) circuit built with basic spice primitives that demonstrates the issue.
KiCad Version
Application: KiCad Schematic Editor x86_64 on x86_64
Version: 7.99.0-3956-g4844cffc00-dirty-4844cffc00~176~ubuntu23.10.1, release build
Libraries:
wxWidgets 3.2.4
FreeType 2.13.2
HarfBuzz 8.0.1
FontConfig 2.14.2
libcurl/8.4.0 OpenSSL/3.0.12 zlib/1.2.13 brotli/1.1.0 zstd/1.5.5 libidn2/2.3.4 libpsl/0.21.2 (+libidn2/2.3.4) libssh2/1.11.0 nghttp2/1.58.0 librtmp/2.3 OpenLDAP/2.5.13
Platform: Debian GNU/Linux trixie/sid, 64 bit, Little endian, wxGTK, X11, KDE, x11
Build Info:
Date: Dec 15 2023 14:38:36
wxWidgets: 3.2.4 (wchar_t,wx containers) GTK+ 3.24
Boost: 1.74.0
OCC: 7.6.3
Curl: 8.4.0
ngspice: 41
Compiler: GCC 13.2.0 with C++ ABI 1018
Build settings: