Skip to content
Browse files

Merge pull request #128 from BrianDoig/master

Fix memory leak in DTHTMLAttributedStringBuilder
  • Loading branch information...
2 parents 8abf37f + 380036c commit ca0e37c2281ff08df51b07cefb77f87a53c2acb1 @odrobnik odrobnik committed Feb 19, 2012
Showing with 19 additions and 10 deletions.
  1. +5 −1 Core/Source/NSAttributedString+HTML.m
  2. +14 −9 Core/Source/UIDevice+DTVersion.m
View
6 Core/Source/NSAttributedString+HTML.m
@@ -76,7 +76,11 @@ - (id)initWithHTML:(NSData *)data options:(NSDictionary *)options documentAttrib
[stringBuilder buildString];
- return [stringBuilder generatedAttributedString];
+ // This needs to be on a seprate line so that ARC can handle releasing the object properly
+ // return [stringBuilder generatedAttributedString]; shows leak in instruments
+ id string = [stringBuilder generatedAttributedString];
+
+ return string;
}
@end
View
23 Core/Source/UIDevice+DTVersion.m
@@ -12,16 +12,21 @@ @implementation UIDevice (DTVersion)
- (DTVersion) osVersion
{
- NSString *versionString = [self systemVersion];
- NSArray *parts = [versionString componentsSeparatedByString:@"."];
+ static DTVersion retVersion;
- DTVersion retVersion;
-
- NSUInteger partCount = [parts count];
-
- retVersion.major = (partCount>0)?[[parts objectAtIndex:0] intValue]:0;
- retVersion.minor = (partCount>1)?[[parts objectAtIndex:1] intValue]:0;
- retVersion.point = (partCount>2)?[[parts objectAtIndex:2] intValue]:0;
+ static dispatch_once_t onceToken;
+ dispatch_once(&onceToken, ^{
+ NSString* versionString = [self systemVersion];
+ NSArray *parts = [versionString componentsSeparatedByString:@"."];
+
+ DTVersion retVersion;
+
+ NSUInteger partCount = [parts count];
+
+ retVersion.major = (partCount>0)?[[parts objectAtIndex:0] intValue]:0;
+ retVersion.minor = (partCount>1)?[[parts objectAtIndex:1] intValue]:0;
+ retVersion.point = (partCount>2)?[[parts objectAtIndex:2] intValue]:0;
+ });
return retVersion;
}

0 comments on commit ca0e37c

Please sign in to comment.
Something went wrong with that request. Please try again.