I'm adding functionality to an existing Cocoa application written mostly in Objective-C. I have to use an existing c++ class in the class I'm writing, so the new class is Objective-C++. Furthermore, I've had to write a method on the c++ class that temporarily uses a buffer. So my c++ method is something like
(void) myMethod{
int8_t* bffr = new int8_t[length];
// use the buffer
delete [] bffr;
}
I instantiate the c++ class in my .mm file, and try to carry on. The problem is that the application crashes. However, if I comment out the delete, the app does not crash, but Instruments reports a leak associated with this method. I presume that the Objective-C memory management is getting bolluxed up. How can I resolve this catch-22?
BTW, I get the same result using malloc and get_temporary_buffer.