Thank you, I've tested those codes and learnt something more about threads. Wanting an Objective C solution (just to learn this superset too, without having to port this code on other platforms), I found my error and resolved.
There was still a series of warnings about memory leaking, so surfing on the web I found what an NSAutoreleasePool is and I used it to do threaded stuff and release it at the end.
Now, threading my process, I came to another problem:
* __NSAutoreleaseNoPool(): Object 0x3174e0 of class MemoryAccess autoreleased with no pool in place - just leaking
^-- this and similar errors, like
* __NSAutoreleaseNoPool(): Object 0x30f600 of class NSCFString autoreleased with no pool in place - just leaking
I haven't written the MemoryAccess class, nor is present within my threaded code. I suspect that threading my process may lead to something unwanted within various threads? I'm not sure about that.
The question is: how to find where this class is missing of NSAutoreleasePools?
This is my actual code:
mainLoop evocation:
NSAutoreleasePool *mainLoopPool = [[NSAutoreleasePool alloc] init];
[NSThread detachNewThreadSelector:@selector(mainLoop) toTarget:self withObject:nil];
[mainLoopPool release];
mainLoop method:
- (void) mainLoop {
int nLoop = LOOP_NULL;
NSAutoreleasePool *subLoopPool;
while (/* loop conditions */) {
subLoopPool = [[NSAutoreleasePool alloc] init];
if(nLoop != LOOP_EVENT1 && /* event1 conditions */) {
NSLog(@"LOOP: Entering event1 Loop");
nLoop = LOOP_EVENT1;
[self performSelector:@selector(event1Loop) onThread:[NSThread currentThread] withObject:nil waitUntilDone:YES];
}
else if(nLoop != LOOP_EVENT2 && /* event2 conditions */) {
NSLog(@"LOOP: Entering event2 Loop");
nLoop = LOOP_EVENT2;
[self performSelector:@selector(event2Loop) onThread:[NSThread currentThread] withObject:nil waitUntilDone:YES];
[subLoopPool release];
}
[subLoopPool release];
}
}
For now event1/2Loop methods are just infinite while cycles with no functions evocated in but the conditional ones.
After a while the program crashes due to
Thread 0 Crashed: Dispatch queue: com.apple.main-thread
0 libobjc.A.dylib 0x93720ed7 objc_msgSend + 23
1 com.apple.CoreFoundation 0x967f50ed _CFAutoreleasePoolPop + 253
...
There are something like 20 autoreleasepool errors, then the log "LOOP: Entering event1 loop"
Thanks.