安装valgrind
参考官方安装指南
使用如下命令行安装
git clone https://sourceware.org/git/valgrind.git
cd valgrind
apt-get install autotools-dev
apt-get install automake
./autogen.sh
./configure
make && make install
在pybind11里使用
参考Using valgrind with cython Identifying memory leaks in cython with valgrind,从以下地址下载valgrind-python.supp
uncomment掉PyObject_Free
和PyObject_Realloc
相关的行
valgrind --tool=memcheck --leak-check=full \
--suppressions=valgrind-python.supp --log-file=minimal.valgrind.log \
python <python代码>