Hi,
I have three layers, the bottom layer is written in C++ and the other two middle and top layers are both in Objective-C.
The C++ layer stores a reference to a class in the middle layer, and the middle layer also stores a reference to a class in the top layer.
Upon receiving a request from the middle layer, the bottom layer is responsible for asynchronously call a method in the middle layer which in turns call a method in the top layer.
Unfortunately, my code reports errors like:
* _NSAutoreleaseNoPool(): Object 0x523e50 of class NSCFNumber autoreleased with no pool in place - just leaking Stack: (0x95c83f0f 0x95b90442 0x28d3 0x2d42 0x95b96e0d 0x95b969b4 0x93a00155 0x93a00012)
The problem is that the method in the top layer was called from a C++ POSIX thread which has no autorelease pool. The only solution I could come up is add the following in the middle layer:
bool temp = false;
- (void) method ...
{
if (!temp)
{
temp = true;
NSAutoreleasePool *arPool = [[NSAutoreleasePool alloc] init];
}
call_to_the_top_layer();
}
This works. My question is that would there be any other better solution? This is ugly...