• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Threads, safeness, and AutoreleasePools
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Threads, safeness, and AutoreleasePools


  • Subject: Threads, safeness, and AutoreleasePools
  • From: Todd Heberlein <email@hidden>
  • Date: Tue, 14 Aug 2001 19:59:05 -0700

I have been experimenting with NSThreads, and I had a couple questions. At
the bottom is a sample method I am testing. It is executed in a new thread
with the detachNewThread:Selector:toTarget:withObject: method.

First, does Apple discourage us from sending a message to an AppKit object
from a separate thread? For example, in the code below I send the
setIntvalue to an NSTextField object. Is this OK? Are there other steps I
should do?

The display mostly works, but sometimes the text gets a little messed up.

Second, I had to create an AutoreleasePool to prevent the program
complaining about a leak when I send the setInt message. I assume it
allocates and releases objects within the method.

Is it common to create an AutoreleasePool for a new thread?

- (void)runInThread
{
NSAutoreleasePool *subpool = [[NSAutoreleasePool alloc] init];

while (in_run_mode == YES) {
count++;
[count_field setIntValue: count];
}
[subpool release];
}

Thanks,

Todd


  • Follow-Ups:
    • Re: Threads, safeness, and AutoreleasePools
      • From: Raphael Sebbe <email@hidden>
  • Prev by Date: Re: TCPDump porting issues
  • Next by Date: Re: E-Mail
  • Previous by thread: Re: cocoa-dev digest, Vol 1 #401 - 15 msgs
  • Next by thread: Re: Threads, safeness, and AutoreleasePools
  • Index(es):
    • Date
    • Thread