Note that there are some explanatory texts on larger screens.

plurals
  1. PONSDateFormatter causing zombie woes
    text
    copied!<p>I've always had some issues getting the infamously picky NSDateFormatter from causing memory instability in my code. I must not grasp how to use it properly. I've looked at tons of sample code and modeled my method after this, but it seems memory issues still plague me. The issues I'm having is that this method is creating a zombie - not too sure how / why. Some insight would be wonderful!! </p> <pre><code>-(NSString *)getTimeZoneFormatedDate:(int)subtractMinutes TimeZoneOffset:(NSString *)timeZoneOffset { float timeZoneOffsetInt = [timeZoneOffset floatValue]; //Calculate the requested UTC time NSDate *UTCDateTimeNow = [NSDate date]; NSDate *UTCDateTimePast = [UTCDateTimeNow dateByAddingTimeInterval:((subtractMinutes*60)+(timeZoneOffsetInt*60*60))]; //Round the minutes down NSDateComponents *time = [[NSCalendar currentCalendar] components:NSHourCalendarUnit | NSMinuteCalendarUnit fromDate:UTCDateTimePast]; int minutes = [time minute]; float minuteUnit = floorf((float) minutes / 10); minutes = minuteUnit * 10; //Format the minutes string NSString *minuteString; minuteString = [NSString stringWithFormat:@"%d",minutes]; if ([minuteString length] &lt; 2) minuteString = [@"0" stringByAppendingString:minuteString]; //Format the rest of the date &amp; time NSTimeZone *timeZone = [NSTimeZone timeZoneWithName:@"UTC"]; NSDateFormatter *dateFormatter; dateFormatter = [[[NSDateFormatter alloc] init] autorelease]; [dateFormatter setTimeZone:timeZone]; [dateFormatter setDateFormat:@"yyyy-MM-dd, HH:"]; NSString *yearMonthDayHourString = [dateFormatter stringFromDate:UTCDateTimePast]; //Put the two together and return it! return [yearMonthDayHourString stringByAppendingString:minuteString]; } </code></pre> <p>I'm implementing it like so:</p> <pre><code> NSString *timeZoneText = [self getTimeZoneFormatedDate:minuteModifier*-10 TimeZoneOffset:radarTimeZoneOffset]; </code></pre> <p>If I run my project with the dateformatter commented out and my method just returning:</p> <pre><code>return @"blah blah"; </code></pre> <p>No issues - everything runs bug free. So, I believe it's safe to assume the issue lies within! Thanks for the help!</p>
 

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