<html><body><div style="color:#000; background-color:#fff; font-family:HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif;font-size:10pt"><div id="yiv9088597543"><div><div style="color:#000;background-color:#fff;font-family:HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif;font-size:10pt;"><div id="yiv9088597543"><div id="yiv9088597543yui_3_13_0_ym1_1_1395526721336_2996"><div class="yiv9088597543yui_3_13_0_ym1_1_1395526721336_2795" id="yiv9088597543yui_3_13_0_ym1_1_1395526721336_2995" style="color:#000;background-color:#fff;font-family:HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif;font-size:10pt;">Thanks for your reply..I can't rewrite the C wrapper for the C++ function so  I wrote  a delete wrapper like the below because I was getting a warning when it didn't have the char* and I heard you could  also use char* explicitly to remove warning.  My defcfun is
 standard it accepts a :pointer and returns void....I use it in my programs wherever memory need to get deleted ...I'm pretty good at knowing where to put the memory freeing functions but I still am getting memory leaks that make me have to restart.The memory I'm trying to free is a Mat*, Mat is an OpenCV c++ class...any help is appreciated<br><br>void delete_ptr(void* ptr) {<br>    delete (char*)ptr;<br>}<br><br><br><div class="yiv9088597543yqt2883171608" id="yiv9088597543yqt58045"><div class="yiv9088597543yqt8851980953" id="yiv9088597543yqt02477"><div class="yiv9088597543yahoo_quoted" id="yiv9088597543yui_3_13_0_ym1_8_1395523935480_15" style="display: block;"> <br clear="none"> <br clear="none"> <div class="yiv9088597543yui_3_13_0_ym1_1_1395523935480_3261 yiv9088597543yui_3_13_0_ym1_1_1395526721336_2800" id="yiv9088597543yui_3_13_0_ym1_1_1395523935480_3408" style="font-family:HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida
 Grande, sans-serif;font-size:10pt;"> <div class="yiv9088597543yui_3_13_0_ym1_1_1395523935480_3262 yiv9088597543yui_3_13_0_ym1_1_1395526721336_2801" id="yiv9088597543yui_3_13_0_ym1_1_1395523935480_3407" style="font-family:HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif;font-size:12pt;"> <div dir="ltr" id="yiv9088597543yui_3_13_0_ym1_1_1395523935480_3451"> <font id="yiv9088597543yui_3_13_0_ym1_1_1395523935480_3452" face="Arial" size="2"> On Saturday, March 22, 2014 2:31 PM, Daniel Herring <dherring@tentpost.com> wrote:<br clear="none"> </font> </div> <blockquote id="yiv9088597543yui_3_13_0_ym1_1_1395523935480_3406" style="border-left:2px solid rgb(16, 16, 255);margin-left:5px;margin-top:5px;padding-left:5px;">  <div class="yiv9088597543y_msg_container" id="yiv9088597543yui_3_13_0_ym1_1_1395523935480_3405">On Sat, 22 Mar 2014, Joeish W wrote:<div class="yiv9088597543yqt6583572295" id="yiv9088597543yqtfd74373"><br
 clear="none"><br clear="none">> I have a whole list of C wrappers for OpenCV C++ functions like the one below. And all of them return a "new".  I can't change them because they are becoming part of OpenCV and it would make my library perfect to have a consistently<br clear="none">> updated skeleton to wrap around. My question is in this case how would one of you free these "new" memory allocators...When I run them in any kind of
 loop.  It just eats up my ram, I
 end up having to restart my pc. Should I make a<br clear="none">> "delete" wrapper and use that.<br clear="none">> I've tried using foreign-free but I still have the same issue of having to restart. Any help is appreciated.<br clear="none">> <br clear="none">> Mat* cv_create_Mat() {<br clear="none">>     return new Mat();</div><br clear="none">> }<br clear="none"><br clear="none"><br clear="none">Hi Joeish,<br clear="none"><br clear="none">Long story short, you need to follow new() with delete().<br clear="none"><br clear="none">C++ new() and delete() extend C's malloc() and free() in roughly the <br clear="none">following way.<br clear="none"><br clear="none">T * new(args) {<br clear="none">   T *x=(T *)malloc(sizeof(T));<br clear="none">   x->T(args); // constructor (aka ctor)<br clear="none">   return x;<br clear="none">}<br clear="none"><br clear="none">void delete(T *x) {<br clear="none">  
 if(x) {<br clear="none">     x->~T(); // destructor (aka dtor)<br clear="none">     free(x);<br clear="none">   }<br clear="none">}<br clear="none"><br clear="none">Note that both the constructor and destructor are fairly arbitrary <br clear="none">functions, and it is common for them to do additional memory management.<br clear="none"><br clear="none"><br clear="none">- Daniel<br clear="none"><br clear="none"></div> </blockquote>  </div> </div>   </div></div></div> </div></div></div></div></div></div></div></body></html>