discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSOperationQueue exception in 1.24.9 - question


From: Richard Frith-Macdonald
Subject: Re: NSOperationQueue exception in 1.24.9 - question
Date: Mon, 3 Apr 2017 21:27:44 +0100

> On 31 Mar 2017, at 19:16, Lobron, David <dlobron@akamai.com> wrote:
> 
> Hi All,
> 
> I recently upgraded to gnustep-base-1.24.9.  As part of the upgrade, I ran a 
> test that repeatedly adds 3,000 operations to an NSOperationQueue.  The 
> operations do not do anything- they are just a subclass of NSOperation with 
> an empty main method:
> 
> @implementation TheOperation
> - (void)main
> {
> }
> @end
> 
> The test is simply:
> 
>    NSLog(@"Frobnicating, pass %u...", _pass);
>    for (i = 0; i < _numOperations; i++) {
>        TheOperation *op = [TheOperation new];
>        [q addOperation:op];
>        [op release];
>    }
>    [q waitUntilAllOperationsAreFinished];
>    NSLog(@"Frobnication took %.3f sec", -[start timeIntervalSinceNow]);
> 
> My program (attached for reference) runs this repeatedly until it's killed 
> with a signal.  Normally, I can run it at least 10,000 times without a 
> problem, but since upgrading to 1.24.9, I'm finding that this code crashes 
> after 2,796 runs, with the following error from NSObject.m, at line 536:
> 
> NSIncrementExtraRefCount() asked to increment too far
> 
> I set a breakpoint on that error message, and got a stack trace (copied 
> below) which suggests that NSMutableDictionary's setObject:forKey: is being 
> called too many times with the same object from NSKeyValueObserving's 
> notifyForKey: (NSString *)aKey ofInstance: (id)instance prior: (BOOL)f 
> method.  However, I compared the code for that method in 1.24.9 with the code 
> in an older gnustep-base, and I don't see any changes.
> 
> Does anyone know of a recent change that might have broken a behavior here?  
> 
> Thanks,
> 
> David
> 
> Stack trace from when the breakpoint on NSObject.m error at line 536:
> 
> #0  NSIncrementExtraRefCount (anObject=0x6a24b0) at NSObject.m:536
> #1  -[NSObject retain] (self=0x6a24b0, _cmd=0x7ffff7ce5710 
> <_OBJC_SELECTOR_TABLE+80>) at NSObject.m:1924
> #2  0x00007ffff77afdb1 in -[GSMutableDictionary setObject:forKey:] 
> (self=0x2511d8fd0, _cmd=<optimized out>, anObject=0x6a24b0, 
> aKey=0x7ffff7d47dc0 <_OBJC_INSTANCE_2>)
>    at GSDictionary.m:452
> #3  0x00007ffff78a3a13 in -[GSKVOPathInfo notifyForKey:ofInstance:prior:] 
> (self=0x2511e3780, _cmd=<optimized out>, aKey=0x7ffff7d5d100 
> <_OBJC_INSTANCE_3>, 
>    instance=0x25131a6d0, f=<optimized out>) at NSKeyValueObserving.m:1064
> #4  0x00007ffff78a44c5 in -[NSObject(NSKeyValueObserverNotification) 
> didChangeValueForKey:] (self=0x25131a6d0, _cmd=<optimized out>, 
>    aKey=0x7ffff7d5d100 <_OBJC_INSTANCE_3>) at NSKeyValueObserving.m:1754
> #5  0x00007ffff78c6274 in -[NSOperation(Private) _finish] (self=0x25131a6d0, 
> _cmd=<optimized out>) at NSOperation.m:528
> #6  0x00007ffff78c89b3 in -[NSOperationQueue(Private) _thread] 
> (self=0x250f39a80, _cmd=<optimized out>) at NSOperation.m:981
> #7  0x00007ffff7930dd1 in nsthreadLauncher (thread=0x2512b2f30) at 
> NSThread.m:1208
> #8  0x00007ffff6a4e192 in start_thread (arg=0x7fff547e0700) at 
> pthread_create.c:312
> #9  0x00007ffff716a4ed in clone () at 
> ../sysdeps/unix/sysv/linux/x86_64/clone.S:111
> 
> <OpQueueTest.m>

Thanks very much for that.  The test program was very helpful and I was able to 
(almost) reproduce the problem and (eventually) track down and fix the issue.
The problem was with the key value observation, by the operation, of itself 
finishing ... the code 3was failing to remove the observatiopn, resulting in 
the operation/observation being leaked, which in turn resulted in the path name 
being retained each time an operation was leaked, so the retain count on your 
machine got too high (on my machine I ran out of memory before hitting the 
retain count limit).

Please try the code in svn trunk ... it should be fixed.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]