I've run into a strange problem with a memory leak, apparently associated with 
setting the text of UILabels.  Googling for /UILabel memory leak/ shows several 
other people having come up against similar problems, both with and without 
ARC, but no solution.

My app (built with ARC) uses a timer to update a display of various components 
of the time once a second.  In Instruments, the Allocations tool reports a slow 
but steady increase in persistent memory allocations of a single size, although 
Leaks reports nothing.  I've tried the iPad2 and iPhone6 simulators, both with 
iOS 8.4.  Both show this leakage, although at different rates and with 
allocations of different sizes.

There are three UILabels that the app updates on every timer event. Commenting 
out the three lines of code that look like this:

        [[self someUILabel] setText: resultOfADateFormatter];

where someUILabel is the name of one of the three UILabel properties, removes 
the leak.  (All of the code that gets the date and formats it in three 
different ways is still enabled.)  Enabling any one of those three lines brings 
the leak back.  In the background, the app does not update the labels or 
receive timer events, and does not leak.

The labels are declared as properties of my single view controller (by code 
automatically generated by Xcode when I set up the storyboard) as:

        @property (weak, nonatomic) IBOutlet UILabel *timestring;
        @property (weak, nonatomic) IBOutlet UILabel *daystring;
        @property (weak, nonatomic) IBOutlet UILabel *yearstring;

The rate of leakage is the same whether I am updating only one label on each 
timer event or all three. If I reduce the timer interval from 1 second to 0.1 
seconds, the rate of leakage increases by a factor of about 6. Definitely less 
than 10.

The analyzer reports nothing, and building and validating an archive reports 
nothing.

Is this a problem I can fix?  Or is it a bug in Instruments, in the simulators, 
or in iOS?

-- Richard Kennaway

-- 
Richard Kennaway, rich...@kennaway.org.uk, http://www.cmp.uea.ac.uk/~jrk/
School of Computing Sciences,
University of East Anglia, Norwich NR4 7TJ, U.K.


_______________________________________________

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