I’m working (at least trying…) on a Cocoa application, which uses several custom Cocoa frameworks and one of these frameworks is a mix of C++ and Objective C++ (mostly C++) code… The problem is that each memory deallocation inside this framework gives me the Pointer being freed was not allocated error, even in the following trivial case:
class testClass
{
public:
testClass() { }
virtual ~testClass() { }
};
void test()
{
testClass *p = new testClass();
delete p;
// malloc: *** error for object 0x2800510: pointer being freed was not allocated
//*** set a breakpoint in malloc_error_break to debug
p = NULL;
}
malloc_error_break tells me that the object’s destructor is being called, however every next allocation increases the object’s address, so the memory is really not being freed… Please tell me, WHY?!
I have to use Mac OS X 10.6.0, XCode 3.2.1, Apple GCC 4.2.1.
Is there a chance, that one of these custom frameworks redefines
newand/ordelete? Try to add this replacements to your test program and look if a) the test program builds without complaining about multiple definitions of new and/or delete and b) it runs and shows a delete for every new?