title: Threaded Obj-C code with ARC enabled -- why it works this way?
body: <p>I need an extra thread in background to listen to requests from socket.</p>
  
  <p>The code is put into a singleton class; it will be called in main.m before NSApplicationMain() like this:</p>
  
  <pre><code> [[SKSocketThread getSingleton] runThread];
  </code></pre>
  
  <p>And runThread is defined as follow:</p>
  
  <pre><code>- (void) runThread {
      [NSThread detachNewThreadSelector:@selector(socketThreadMainLoop:)
                               toTarget:self
                             withObject:[self quitLock]];
  }
  
  - (void) socketThreadMainLoop:(id)param {
      NSLock *lock = (NSLock *)param;
      while (![lock tryLock]) {
          NSLog(@"Yay! We are in socketThreadMainLoop now!");
          [NSThread sleepForTimeInterval:2];
      }
      NSLog(@"Terminating the socket thread...");
      [lock unlock]; // is it really necessary?
  }
  </code></pre>
  
  <p>It compiled successfully with no warning, but will throw an error in runtime:</p>
  
  <pre><code>autoreleased with no pool in place.
  </code></pre>
  
  <p>I did some googling, tried to pack code in runThread and socketThreadMainLoop with @autoreleasepool, but the error is still there. Finally I wrapped call to runThread with it in main.m, and that worked!</p>
  
  <p>I don't know why it only works this way...</p>