ZBar crashing with multiple use in iOS7

Barry Mc S
  • Barry Mc S
    Barry Mc S

    I have an app that scans barcodes as part of a workflow that is one of several views controlled by a UINavigationController. I'm experiencing that on the 6th/7th time I enter the screen that the app uses up 100% of the CPU and after a few moments, crashes with an out of memory error. This has only happened since upgrading to XCode 5 and iOS7.

    Here is my initialization code called every time the screen loads:
    reader = [ZBarReaderViewController new];
    reader.readerDelegate = self;

    reader.cameraOverlayView = scanView;
    reader.showsCameraControls = NO;
    reader.showsZBarControls = NO;
    [reader.readerView setScanCrop:(CGRect){ { 0, 0 }, { 0.25, 1 } }];
    ZBarImageScanner *scanner = reader.scanner;
    // TODO: (optional) additional reader configuration here
    // EXAMPLE: disable rarely used I2/5 to improve performance
    [scanner setSymbology: ZBAR_I25
                   config: ZBAR_CFG_ENABLE
                       to: 0];
    // present and release the controller
    [self presentViewController:reader animated:YES completion:nil];

    And here is my remove code for the controller.

    [reader dismissModalViewControllerAnimated: YES];
  • Barry Mc S
    Barry Mc S

    It's been reported that this has been fixed by creating ZBarReaderViewController *readerqr; as a property of your viewcontroller.

    However I have done that and I'm still experiencing the issue.

    @interface SSMyViewController : UIViewController {

    ZBarReaderViewController *readerqr;

    @property ZBarReaderViewController *readerqr;

    Does anyone have any tips as to what might be missing?

  • appdev

    I was running into this exact problem. Right around the 6th scan, 100% CPU, memory explosion, app unresponsive when using ZBarReaderViewController.

    There's a thread on the apple dev forums semi-related---but---apple came back(right or wrong) "that there was a bug in the ZBar code. Specifically, in ZBarReaderViewController. readerView is created (alloc init, +1 for retain) and added to view (+1 retain), and only released once during tear down."

    (The questionable/challenging part of that statement is why would that suddenly start happening in 7 versus 6)

    In any case, the only workable solution i found(without rebuilding the SDK myself with the above change), was to convert to using ZBarReaderView. Once I did that, everything worked properly.

  • optme1

    @appdev. Can you please post the lines of code you changed. I can rebuild SDK and try.

  • appdev

    @optme1---My apologies, I should have properly said without attempting to rebuild...I'm afraid I switched over to using ZBarReaderView and ripped out the customized version of the SDK I built prior to giving those particular suggestions a try. I could hazard a guess where that release might go but I think i might step dangerously close to talking out of my ass.

    spadix might have some thoughts on where that release should go -- if that actually is the problem.

    Last edit: appdev 2013-09-26
  • appdev

    @cchilds--Thanks...Unfortunately, for me, adding the autorelease in that noted in the patch when I tried it out last week, had no impact on addressing the issue I was seeing with CPU and memory. It's probably worth another try for someone--but sadly, didn't seem to do the trick for me.

  • Stephen Groom
    Stephen Groom

    ^^ You have linked to a stackoverflow question, not a solution. Also, every answer in that question seems to be a workaround and not a fix.

    I am having the same issue with ZBarReaderView FWIW and would love some direction on where to look for the leak

  • I have attached the patch I'm currently using. The Leaks instrument no longer shows any leaks during scanning for me.

    I currently dismiss the ZBarReaderViewController during each call to:

    - (void) imagePickerController: (UIImagePickerController) reader didFinishPickingMediaWithInfo: (NSDictionary) info

    and then create a new one and redisplay it if I want to continue scanning. I do seem to recall a more serious memory leak and hang when I wasn't doing this (but this was the workflow my boss wanted anyway, so that worked out well :-)

    If you are still seeing problems, you might try running under leaks and seeing what it is reporting...

    Last edit: Joseph Galbraith 2013-12-11