Note that there are some explanatory texts on larger screens.

plurals
  1. POWeird leaks in UIPickerView methods
    primarykey
    data
    text
    <p>Building a custom UIPickerView for so I can let my users select time as 24 hours without having to go into the Settings app and turn on 24 hour time for the entire phone. Got some stubborn leaks of a couple strings and an array, and I could really use some help.</p> <p>There are only three places where the arrays I'm creating with the strings are used. hours and minutes are both <code>NSArray</code> synthesized properties as well as ivars. </p> <p>a) In viewWillAppear:animated, where the strings and arrays are actually created: </p> <pre><code>if (TwentyFourHourMode) { //set up arrays for 24 hour picker NSMutableArray *hoursMutable = [[NSMutableArray alloc] init]; NSString *hourString; for (int i = 0; i &lt; 24; i++) { if (i &lt; 10) { hourString = [NSString stringWithFormat:@"0%i", i]; } else { hourString = [NSString stringWithFormat:@"%i", i]; } [hoursMutable addObject:hourString]; } self.hours = [[NSArray alloc] initWithArray:hoursMutable]; [hoursMutable release]; NSMutableArray *minutesMutable = [[NSMutableArray alloc] init]; NSString *minuteString; for (int i = 0; i &lt; 60; i++) { if (i &lt; 10) { minuteString = [NSString stringWithFormat:@"0%i", i]; } else { minuteString= [NSString stringWithFormat:@"%i", i]; } [minutesMutable addObject:minuteString]; } self.minutes = [[NSArray alloc] initWithArray:minutesMutable]; [minutesMutable release]; //more stuff which does not leak or reference the arrays/strings in question } else { //unrelated crap } </code></pre> <p>b) in my UIPickerView delegate methods - everything that uses these two arrays:</p> <pre><code>-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView { return 2; } -(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component { if (component == 0) { return self.hours.count; } else if (component == 1) { return self.minutes.count; } else { return 0; } } - (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component { if (component == 0) { return [self.hours objectAtIndex:row]; } else if (component == 1) { return [self.minutes objectAtIndex:row]; } else { return nil; } } - (CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component { switch(component) { case 0: return 44; case 1: return 50; default: return 44; } } - (void) pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component { if (component == 0) { [hour24 release]; hour24 = [self.hours objectAtIndex:row]; [hour24 retain]; } else if (component == 1) { [minute24 release]; minute24 = [self.minutes objectAtIndex:row]; [minute24 retain]; } </code></pre> <p>c) and last but not least, in dealloc:</p> <pre><code>//set arrays to nil self.hours = nil; self.minutes = nil; //release arrays [hours release]; [minutes release]; </code></pre> <p>Analyze is coming up clean, but Instruments is telling me hourString, minuteString, and self.hours are all being leaked. What really drives me nuts is that self.minutes isn't being leaked and it appears to be the same format of code as self.hours - I even copy-pasted and still get the same leak/no leak combo. </p> <p>I'll be damned if I can figure out where this is coming from. Any ideas? Any further code y'all might need to help? Thanks, guys!</p> <p><strong>Edit</strong>: EmptyStack's suggestion stopped <code>self.hours</code> and <code>minuteString</code> from being leaked, but <code>hourString</code> is still leaking and there's now a new leak in this code just below the stuff above in <code>viewWillAppear:animated</code> (<code>self.incomingTime</code> is a synthesized <code>NSString</code> property, all arrays here are initialized locally): </p> <pre><code>NSArray *splitStrings = [self.incomingTime componentsSeparatedByString:@":"]; NSString *hourToDisplay = [splitStrings objectAtIndex:0]; //set this here so it doesn't give a null value hour24 = [[NSString alloc] initWithString:hourToDisplay]; NSString *minuteSplitter = [splitStrings objectAtIndex:1]; NSArray *splitMinutes = [minuteSplitter componentsSeparatedByString:@" "]; NSString *minuteToDisplay = [splitMinutes objectAtIndex:0]; minute24 = [[NSString alloc] initWithString:minuteToDisplay]; </code></pre> <p><strong>Edit 2:</strong> Oh, for crying out loud, now <code>minuteString</code> is leaking again. I'm going to bed before my head explodes. Any suggestions overnight would be most welcome. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload