> On 4 Sep 2015, at 01:21, Quincey Morris <quinceymor...@rivergatesoftware.com> 
> wrote:
> 
> Two thoughts about this.
> 
> 1. Are you sure that ‘updateTime’ is running on the main thread? It needs to 
> be, since you’re updating the UI directly from this code.

Yes, according to calling

        NSLog( @"isCurThr: %d", [[NSThread currentThread] isMainThread] );

from updateTime.  The project is a very simple one anyway, built from scratch, 
and works perfectly apart from this issue.  I am perplexed at how something so 
simple can go wrong in such a subtle way.

> 2. The code inside ‘updateTime’ is very self-contained, so it seems easy to 
> try a divide-and-conquer strategy. What happens if you remove all the code, 
> so that the method consists of empty braces? What happens if you don’t format 
> anything, but simply set the UILabel fields to a constant string each time?
> 
> My guess is that the problem will persist regardless of what the method does, 
> and the problem is elsewhere. But at least it would be useful to rule this 
> method’s code out, if you can.

I made a minimal version of the project that leaves out all of the date 
formatting stuff and just updates several UILabels when the timer fires.

- (void)updateLabels {
    ++numticks;
    [[self label1] setText: [NSString stringWithFormat:@"%@ %d", @"label1", 
numticks]];
    [[self label2] setText: [NSString stringWithFormat:@"%@ %d", @"label2", 
numticks]];
    [[self label3] setText: [NSString stringWithFormat:@"%@ %d", @"label3", 
numticks]];
    [[self label4] setText: [NSString stringWithFormat:@"%@ %d", @"label4", 
numticks]];
    [[self label5] setText: [NSString stringWithFormat:@"%@ %d", @"label5", 
numticks]];
}

If I comment out all of the updates, no leak.  If any of them are enabled, I 
get this leak, at a rate independent of how many are enabled.  I've tried 
constant strings, and strings with a count of ticks appended as above (so I can 
see that the timer is running) and it makes no difference to the leak.

Reducing the timer interval from 1 to 0.1 or 0.01 seconds increases the rate of 
leak, but less than proportionally.   1 second, 3 leaks per second.  0.1 
seconds, 12 per second. 0.01 seconds, 100 per second.  Measuring the tick count 
with a stopwatch, I can tell it isn't missing any significant fraction of 
ticks. (At 0.001 seconds it does.)

There are also a couple of leaks reported by Leaks within the first twenty 
seconds of running.  they dont' accumulate, and Leaks doesn't tell me much 
about them beyond being mallocs of 32 bytes.

If anyone wants to take a look at the whole project, I've put a zip file at
https://www.dropbox.com/s/relxku0iw44o237/TestUILabelLeak.zip

PS. Thanks to whoever unblocked the moderation on the list. My original message 
was submitted three weeks ago.

-- Richard Kennaway
_______________________________________________

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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

Reply via email to