ZBar memory leak on iOS?

前端 未结 3 1665
再見小時候
再見小時候 2021-02-14 07:43

I am very satisfied with ZBar scanning performance, however I ran into a big problem on a project that runs under ARC if that counts at all.

Namely, it seems that there

3条回答
  •  长发绾君心
    2021-02-14 07:55

    I found exactly the same problem with the current stable version of ZBar 0.10, and fixed it by subclassing ZBarReaderViewController and overriding the loadView method. I can now run the scanner over and over without memory going crazy.

    Here's the full code:

    ... header

    #import 
    #import "ZBarReaderViewController.h"
    
    @interface CVZBarReaderViewController : ZBarReaderViewController
    @end
    

    .. and the implementation

    #import "CVZBarReaderViewController.h"
    
    @implementation CVZBarReaderViewController 
    - (void) loadView
    {
        self.view = [[[UIView alloc] initWithFrame: CGRectMake(0, 0, 320, 480)] autorelease];
    }
    @end
    

    Remember to mark the .m file as being non-arc. Go to Project Settings / Target / Build Phases / Compile Sources and mark CVZBarReaderViewController.m with -fno-objc-arc.

提交回复
热议问题