[iphone] fixed minor memory leaks

git-svn-id: https://zxing.googlecode.com/svn/trunk@1727 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
rpechayr 2011-03-16 15:57:43 +00:00
parent 13403613bc
commit 55e3c2418c
9 changed files with 33 additions and 27 deletions

View file

@ -157,7 +157,7 @@ static const CGFloat kPadding = 10;
else { else {
UIFont *font = [UIFont systemFontOfSize:18]; UIFont *font = [UIFont systemFontOfSize:18];
CGSize constraint = CGSizeMake(rect.size.width - 2 * kTextMargin, cropRect.origin.y); CGSize constraint = CGSizeMake(rect.size.width - 2 * kTextMargin, cropRect.origin.y);
CGSize displaySize = [displayedMessage sizeWithFont:font constrainedToSize:constraint]; CGSize displaySize = [self.displayedMessage sizeWithFont:font constrainedToSize:constraint];
CGRect displayRect = CGRectMake((rect.size.width - displaySize.width) / 2 , cropRect.origin.y - displaySize.height, displaySize.width, displaySize.height); CGRect displayRect = CGRectMake((rect.size.width - displaySize.width) / 2 , cropRect.origin.y - displaySize.height, displaySize.width, displaySize.height);
[self.displayedMessage drawInRect:displayRect withFont:font lineBreakMode:UILineBreakModeWordWrap alignment:UITextAlignmentCenter]; [self.displayedMessage drawInRect:displayRect withFont:font lineBreakMode:UILineBreakModeWordWrap alignment:UITextAlignmentCenter];
} }

View file

@ -26,7 +26,7 @@
NSArray *points; NSArray *points;
} }
@property (nonatomic, copy) NSString *text; @property (nonatomic, retain) NSString *text;
@property (nonatomic, retain) NSArray *points; @property (nonatomic, retain) NSArray *points;
+ (id)resultWithText:(NSString *)text points:(NSArray *)points; + (id)resultWithText:(NSString *)text points:(NSArray *)points;

View file

@ -40,7 +40,7 @@
} }
- (id)copyWithZone:(NSZone *)zone { - (id)copyWithZone:(NSZone *)zone {
TwoDDecoderResult *theCopy = [[TwoDDecoderResult allocWithZone:zone] initWithText:[text copyWithZone:zone] points:[points copyWithZone:zone]]; TwoDDecoderResult *theCopy = [[TwoDDecoderResult allocWithZone:zone] initWithText:[text retain] points:[points retain]];
return theCopy; return theCopy;
} }

View file

@ -260,16 +260,13 @@
[self presentResultForString:[twoDResult text]]; [self presentResultForString:[twoDResult text]];
[self presentResultPoints:[twoDResult points] forImage:image usingSubset:subset]; [self presentResultPoints:[twoDResult points] forImage:image usingSubset:subset];
// now, in a selector, call the delegate to give this overlay time to show the points // now, in a selector, call the delegate to give this overlay time to show the points
[self performSelector:@selector(alertDelegate:) withObject:[[twoDResult text] copy] afterDelay:0.0]; [self performSelector:@selector(notifyDelegate:) withObject:[[twoDResult text] copy] afterDelay:0.0];
decoder.delegate = nil; decoder.delegate = nil;
} }
- (void)alertDelegate:(id)text { - (void)notifyDelegate:(id)text {
if (!isStatusBarHidden) if (!isStatusBarHidden) [[UIApplication sharedApplication] setStatusBarHidden:NO];
[[UIApplication sharedApplication] setStatusBarHidden:NO]; [delegate zxingController:self didScanResult:text];
if (delegate != nil) {
[delegate zxingController:self didScanResult:text];
}
[text release]; [text release];
} }

View file

@ -27,7 +27,7 @@
NSString *text; NSString *text;
} }
@property (nonatomic, copy) NSString *text; @property (nonatomic, retain) NSString *text;
- (id)initWithString:(NSString *)s; - (id)initWithString:(NSString *)s;

View file

@ -38,8 +38,8 @@
- (id)initWithURLString:(NSString *)s URL:(NSURL *)ur; - (id)initWithURLString:(NSString *)s URL:(NSURL *)ur;
- (id)initWithURLString:(NSString *)s; - (id)initWithURLString:(NSString *)s;
@property (nonatomic, retain) NSString *urlString; @property (nonatomic, copy) NSString *urlString;
@property (nonatomic, retain) NSString *title; @property (nonatomic, copy) NSString *title;
@property (nonatomic, retain) NSURL *URL; @property (nonatomic, copy) NSURL *URL;
@end @end

View file

@ -81,6 +81,7 @@
- (void)dealloc { - (void)dealloc {
[URL release]; [URL release];
[urlString release]; [urlString release];
[title release];
[super dealloc]; [super dealloc];
} }

View file

@ -77,9 +77,11 @@
} else if ([self characterAtIndex:termRange.location-1] == (unichar)'\\') { } else if ([self characterAtIndex:termRange.location-1] == (unichar)'\\') {
i++; i++;
} else { } else {
NSAutoreleasePool *secondaryPool = [[NSAutoreleasePool alloc] init];
NSString *substring = [self substringWithRange:NSMakeRange(start, termRange.location - start)]; NSString *substring = [self substringWithRange:NSMakeRange(start, termRange.location - start)];
NSString *unescaped = [substring backslashUnescaped]; NSString *unescaped = [substring backslashUnescaped];
NSString *toBeInArray = [[NSString alloc] initWithString:unescaped]; NSString *toBeInArray = [[NSString alloc] initWithString:unescaped];
[secondaryPool release];
if (result == nil) { if (result == nil) {
result = [[NSMutableArray alloc] initWithCapacity:1]; result = [[NSMutableArray alloc] initWithCapacity:1];
} }

View file

@ -39,10 +39,12 @@
if (colonRange.location == NSNotFound) { if (colonRange.location == NSNotFound) {
return [NSString stringWithFormat:@"http://%@", self]; return [NSString stringWithFormat:@"http://%@", self];
} else { } else {
return [NSString stringWithFormat:@"%@%@", NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
[[self substringToIndex:colonRange.location] lowercaseString], NSString *part1 = [[self substringToIndex:colonRange.location] lowercaseString];
[self substringFromIndex:colonRange.location] NSString *part2 = [self substringFromIndex:colonRange.location];
]; NSString *result = [[NSString alloc] initWithFormat:@"%@%@", part1,part2];
[pool release];
return [result autorelease];
} }
} }
@ -58,22 +60,26 @@
} }
+ (ParsedResult *)parsedResultForString:(NSString *)s { + (ParsedResult *)parsedResultForString:(NSString *)s {
NSAutoreleasePool *myPool = [[NSAutoreleasePool alloc] init];
ParsedResult *result = nil;
NSRange prefixRange = [s rangeOfString:PREFIX options:NSCaseInsensitiveSearch]; NSRange prefixRange = [s rangeOfString:PREFIX options:NSCaseInsensitiveSearch];
if (prefixRange.location == 0) { if (prefixRange.location == 0) {
int restStart = /*prefixRange.location + */ prefixRange.length; int restStart = /*prefixRange.location + */ prefixRange.length;
return [[[URIParsedResult alloc] initWithURLString:[[s substringFromIndex:restStart] massagedURLString]] result = [[URIParsedResult alloc] initWithURLString:[[s substringFromIndex:restStart] massagedURLString]];
autorelease]; // return [[[URIParsedResult alloc] initWithURLString:[[s substringFromIndex:restStart] massagedURLString]]
} // autorelease];
} else if ([s looksLikeAURI]) {
if ([s looksLikeAURI]) {
NSString *massaged = [s massagedURLString]; NSString *massaged = [s massagedURLString];
NSURL *url = [NSURL URLWithString:massaged]; NSURL *url = [[NSURL alloc] initWithString:massaged];
if (url != nil) { if (url != nil) {
return [[[URIParsedResult alloc] initWithURLString:massaged URL:url] autorelease]; result = [[URIParsedResult alloc] initWithURLString:massaged URL:url];
} }
[url release];
} }
[myPool release];
return nil; return [result autorelease];
} }