Will memory leaks happen when the MEX file contains new & delete or STL containers (C++)?
Ältere Kommentare anzeigen
Memory Management in documentation says that mxCalloc and mxFree, instead of calloc and free in standard C library, should be used to manage memory.
However, it is sometimes unavoidable to use new & delete when using C++ classes in MEX file, as well as the automatic memory management of STL containers when using them.
Here comes the question. If the user sometimes interrupts the MEX file execution using Ctrl+C, and if the MEX file contains new & delete or STL containers, will memory leaks happen? If so, how to avoid memory leaks (with least extra work)?
2 Kommentare
Why are you worrying about this? It is the kernel that handles the memory that was allocated to a process once it is killed.
https://unix.stackexchange.com/questions/275184/when-interrupting-a-process-does-a-memory-leak-occur
I am presuming something similar occurs in Windows.
Philip Borghesani
am 5 Sep. 2017
Bearbeitet: Philip Borghesani
am 5 Sep. 2017
SIGINT does not apply here. MATLAB will handle SIGINT and will throw a synchronous c++ exception when it is safe to do so. Under no circumstances should a MEX file attempt to install a signal handler doing so will interfere with MATLAB's signal handler and cause never ending grief.
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu C MEX 文件应用程序 finden Sie in Hilfe-Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!