#import #import #import #import #import @interface MyClass:NSObject - test; @end @implementation MyClass - (void)test { [NSThread detachNewThreadSelector:@selector(newThread) toTarget:self withObject:nil]; } - (void)newThread { int i,j; NSAutoreleasePool *pool = [NSAutoreleasePool new]; for(i = 0; i < 1000; i++) { [self performSelectorOnMainThread:@selector(show:) withObject:[NSNumber numberWithInt:i] waitUntilDone:NO]; /* You sohuld use this small loop for a little slowdown (currently none) */ for(j = 0; j < 0; j++) { [NSObject class]; } } RELEASE(pool); } - (void)show:(NSNumber *)number { static int last = 0; if([number intValue] < last) { NSLog(@"NUMBER < LAST (%i < %i)", [number intValue], last); } last = [number intValue]; } @end @class NSAutoreleasePool; int main(int argc, const char **argv) { NSAutoreleasePool *pool; MyClass *obj = [[MyClass alloc] init]; int delay = 5; pool = [NSAutoreleasePool new]; [obj test]; [NSTimer scheduledTimerWithTimeInterval: delay invocation: nil repeats: NO]; [[NSRunLoop currentRunLoop] runUntilDate: [NSDate dateWithTimeIntervalSinceNow: delay]]; RELEASE(obj); RELEASE(pool); return 0; }