Re: App crashes on thread exit
Re: App crashes on thread exit
- Subject: Re: App crashes on thread exit
- From: Cameron Hayne <email@hidden>
- Date: Sat, 12 Oct 2002 16:27:52 -0400
On 12/10/02 1:33 pm, "Fabio Genoese" <email@hidden> wrote:
>
- (void)sThread:(id)address
>
{
>
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
>
NSLock *theLock = [[NSLock alloc] init];
>
Server *s = [[Server alloc] init];
>
NSMutableDictionary *record = [[NSMutableDictionary alloc] init];
>
>
if ([theLock tryLock]) {
>
s = [qstat queryServer:address];
>
record = [s data];
>
[records addObject:record];
>
}
>
[theLock unlock];
>
[pool release];
>
}
Several comments:
1) It seems that qstat & records are ivars. Have you retained them?
2) I don't see the point of having the NSLock here. Usually you create an
NSLock object somewhere before your program becomes multi-threaded - i.e. at
initialization, and then use it in more than one thread.
3) Usually you do the pool alloc & release at the beginning and end of each
thread - not in some short-lived method which gets invoked several times in
the thread. Nothing wrong with doing this as far as I can see, but not
necessary to do it so often.
4) You are overwriting the value of the 'record' pointer you allocated with
the value you get back from [s data].
--
Cameron Hayne (email@hidden)
Hayne of Tintagel
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.