From 8922f5ff2a2fc4b4166d2ca68cb6093c16308867 Mon Sep 17 00:00:00 2001 From: "smparkes@smparkes.net" Date: Wed, 13 Apr 2011 19:47:41 +0000 Subject: [PATCH] cleanup memory issues in decoder/decoder result; a few xcode4 svn tweaks git-svn-id: https://zxing.googlecode.com/svn/trunk@1741 59b500cc-1b3d-0410-9834-0bbf25fbcc57 --- iphone/ScanTest/.gitignore | 1 + iphone/ScanTest/ScanTest.xcodeproj/project.pbxproj | 2 ++ .../project.xcworkspace/contents.xcworkspacedata | 7 +++++++ iphone/ZXingWidget/.gitignore | 1 + iphone/ZXingWidget/Classes/Decoder.mm | 14 ++++++-------- iphone/ZXingWidget/Classes/TwoDDecoderResult.m | 6 ++++-- iphone/ZXingWidget/Classes/ZXingWidgetController.m | 9 +++++---- 7 files changed, 26 insertions(+), 14 deletions(-) create mode 100644 iphone/ScanTest/ScanTest.xcodeproj/project.xcworkspace/contents.xcworkspacedata diff --git a/iphone/ScanTest/.gitignore b/iphone/ScanTest/.gitignore index e1793a939..a96c7a414 100644 --- a/iphone/ScanTest/.gitignore +++ b/iphone/ScanTest/.gitignore @@ -1,3 +1,4 @@ /build /ScanTest.xcodeproj/*.mode1v3 /ScanTest.xcodeproj/*.pbxuser +/ScanTest.xcodeproj/xcuserdata diff --git a/iphone/ScanTest/ScanTest.xcodeproj/project.pbxproj b/iphone/ScanTest/ScanTest.xcodeproj/project.pbxproj index 95173691c..64adf8d84 100755 --- a/iphone/ScanTest/ScanTest.xcodeproj/project.pbxproj +++ b/iphone/ScanTest/ScanTest.xcodeproj/project.pbxproj @@ -285,6 +285,7 @@ OTHER_LDFLAGS = ""; PRESERVE_DEAD_CODE_INITS_AND_TERMS = YES; PRODUCT_NAME = ScanTest; + SDKROOT = iphoneos; STANDARD_C_PLUS_PLUS_LIBRARY_TYPE = dynamic; }; name = Debug; @@ -301,6 +302,7 @@ GCC_SYMBOLS_PRIVATE_EXTERN = NO; INFOPLIST_FILE = "ScanTest-Info.plist"; PRODUCT_NAME = ScanTest; + SDKROOT = iphoneos; VALIDATE_PRODUCT = YES; }; name = Release; diff --git a/iphone/ScanTest/ScanTest.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/iphone/ScanTest/ScanTest.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 000000000..891145758 --- /dev/null +++ b/iphone/ScanTest/ScanTest.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/iphone/ZXingWidget/.gitignore b/iphone/ZXingWidget/.gitignore index ee49cbfcc..5f5068b02 100644 --- a/iphone/ZXingWidget/.gitignore +++ b/iphone/ZXingWidget/.gitignore @@ -1,3 +1,4 @@ /build /ZXingWidget.xcodeproj/*.mode1v3 /ZXingWidget.xcodeproj/*.pbxuser +/ZXingWidget.xcodeproj/xcuserdata diff --git a/iphone/ZXingWidget/Classes/Decoder.mm b/iphone/ZXingWidget/Classes/Decoder.mm index 16df0f5fd..136fdb3c5 100644 --- a/iphone/ZXingWidget/Classes/Decoder.mm +++ b/iphone/ZXingWidget/Classes/Decoder.mm @@ -182,6 +182,8 @@ public: #endif for (FormatReader *reader in formatReaders) { NSAutoreleasePool *secondarypool = [[NSAutoreleasePool alloc] init]; + NSMutableArray *points = nil; + NSString *resultString = nil; try { #ifdef DEBUG NSLog(@"decoding gray image"); @@ -196,8 +198,7 @@ public: Ref resultText(result->getText()); const char *cString = resultText->getText().c_str(); const std::vector > &resultPoints = result->getResultPoints(); - NSMutableArray *points = - [[NSMutableArray alloc ] initWithCapacity:resultPoints.size()]; + points = [[NSMutableArray alloc ] initWithCapacity:resultPoints.size()]; for (size_t i = 0; i < resultPoints.size(); i++) { const Ref &rp = resultPoints[i]; @@ -205,14 +206,9 @@ public: [points addObject:[NSValue valueWithCGPoint:p]]; } - //NSString *resultString = [NSString stringWithCString:cString - // encoding:NSUTF8StringEncoding]; - NSString *resultString = [[NSString alloc] initWithCString:cString encoding:NSUTF8StringEncoding]; - //decoderResult = [[TwoDDecoderResult resultWithText:resultString points:points] retain]; + resultString = [[NSString alloc] initWithCString:cString encoding:NSUTF8StringEncoding]; if (decoderResult) [decoderResult release]; decoderResult = [[TwoDDecoderResult alloc] initWithText:resultString points:points]; - [resultString release]; - [points release]; } catch (ReaderException &rex) { NSLog(@"failed to decode, caught ReaderException '%s'", rex.what()); @@ -222,6 +218,8 @@ public: } catch (...) { NSLog(@"Caught unknown exception!"); } + [resultString release]; + [points release]; [secondarypool release]; } diff --git a/iphone/ZXingWidget/Classes/TwoDDecoderResult.m b/iphone/ZXingWidget/Classes/TwoDDecoderResult.m index 7673cbd8f..136b71ec2 100644 --- a/iphone/ZXingWidget/Classes/TwoDDecoderResult.m +++ b/iphone/ZXingWidget/Classes/TwoDDecoderResult.m @@ -40,8 +40,10 @@ } - (id)copyWithZone:(NSZone *)zone { - TwoDDecoderResult *theCopy = [[TwoDDecoderResult allocWithZone:zone] initWithText:[text retain] points:[points retain]]; - return theCopy; + NSArray* newPoints = [[[NSArray alloc] initWithArray:points] autorelease]; + NSString* newText = [[[NSString alloc] initWithString:text] autorelease]; + + return [[TwoDDecoderResult allocWithZone:zone] initWithText:newText points:newPoints]; } - (id)copy { diff --git a/iphone/ZXingWidget/Classes/ZXingWidgetController.m b/iphone/ZXingWidget/Classes/ZXingWidgetController.m index 6d356db09..2429ae5b3 100755 --- a/iphone/ZXingWidget/Classes/ZXingWidgetController.m +++ b/iphone/ZXingWidget/Classes/ZXingWidgetController.m @@ -419,10 +419,11 @@ didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer cropRect.size.height = CGImageGetHeight(capture); } - // Won't work if the overlay becomes uncentered ... - // iOS always takes videos in landscape - // images are always 4x3; device is not - // iOS uses virtual pixels for non-image stuff + // N.B. + // - Won't work if the overlay becomes uncentered ... + // - iOS always takes videos in landscape + // - images are always 4x3; device is not + // - iOS uses virtual pixels for non-image stuff { float height = CGImageGetHeight(capture);