0

I wrote some C code to create a python module. I wrote the code myself (did not use SWIG etc). If you're interested, the C code is at the bottom of this thread.

Q: Is there any way to (hopefully, easily) find whether my C code has memory leaks? Is there any way to use python's awesomeness for finding memory leaks in its extensions?

Community
  • 1
  • 1
Yair Daon
  • 1,043
  • 2
  • 15
  • 27
  • If on Linux -> [valgrind](http://www.valgrind.org) – Iharob Al Asimi Jan 12 '15 at 16:41
  • 1
    `sys.getrefcount(some_object)` can be helpful for quick sanity checks (e.g. making sure that you don't accidentally increase the refcount of an input object to your function unexpectedly) -- But it isn't a substitute for a leak detecting tool like valgrind. – mgilson Jan 12 '15 at 16:48
  • Similar question which is answered. https://stackoverflow.com/questions/3982036/how-can-i-use-valgrind-with-python-c-extensions – Waqar Rashid Jul 23 '18 at 09:54

1 Answers1

1

if you using a linux environment we can easily find the memory leaks by using debugger named valgrind. To get the valgrind first you have to install it from the internet by using command

sudo apt-get valgrind

after the installation is completed compile your c code using this debugger you can easily find the memory leaks. This debugger shows what is the reason for the memory leak and also specifies the line at which the leak has been occured.