On 19 okt 2009, at 23.37, Graham Cox wrote:

Since there's no autorelease pool inside your do...while loop, of course it isn't going to get autoreleased then. Autorelease isn't magic, someone has to tell it when it can release - that's you. Put your pool inside the loop so it is created and destroyed each time.


In all fairness, this isn't your responsibility for the most part. For high frequency / long lived loops it typically is though.


On 19 okt 2009, at 23.41, Graham Cox wrote:

-(void)newThread
{
  NSAutoreleasePool *pool = [[NSAutoreleasePool alloc]init];


        //Some operations...


        do  //Keeps thread alive till date
        {
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow: 0.1]];

} while (mShouldThreadAlive); //Waiting for other process to complete

 [pool release];

}


Mind you, having said what I just said, this is a bad approach anyway. You should not "keep a thread alive" until it gets some flag, that's just wasting CPU time doing nothing but spinning. Instead the thread should sleep until it has something to do. If you need to wait for another thread to finish, use a NSConditionLock to do it properly. Also, if this code is representative, you are spinning it after all the processing has finished, which is pointless. Just let it terminate if it has nothing more to do.


It's unclear what the purpose of the loop at the end of this method is intended to serve. From the code posted here I would agree with Graham that it seems likely that a condition lock is more appropriate.

Do you need a run loop for some reason? Are you using it to communicate with the thread?

j o a r


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to