in reply to xs memoryleak

How do you know you have a memory leak?

Some tips, dont use XPUSHs, the amount of elements you will push is preknown, do a single EXTEND then do the loop. I try never use malloc or safemalloc or Newx in my XS code. Use alloca, or "char * buf = sv_grow(sv_newmortal(),size);" which is functionally identical but slower. croaks and dies in XS will memory leak all malloced blocks and leak all C++ objects (stack and heap), since free or the c++ destroyer is never called, only Perl SV mortals and C stack allocated bytes will be freed during a perl croak or die (which is implemented with longjmp. You choices for safe XS allocation are alloca, mortal SVs, or package SVs or incoming @_ SVs. I dont see any croaks or dies in your XS code that would cause leaking. I didn't read the C++ function you posted. I would say XS is easy. Your best kept secret debugging is to code format the post c preprocessor output of your XS code. All the secrets of the XS api will be revealed. And of course use a C debugger and compile the XS library with -Od and with symbols.