Memory leak on iOS 10 devices #312
Comments
I've noticed that there appears to be a rather large IOKit allocation in the VM that i'm not sure where it's coming from. You can see here from the VM Summary that with the iPad it is not allocating these 100 MiB chunks, but does so in iOS 10. I'm still not really that sure where this is coming from or what would force these extra calls. It's every time the scanner is executed that one of these 26364 page, 102.88 MiB allocations occurs. This is only happening on the iOS 10 device, and does not appear to be occurring at all on the iPad. |
(Probably) the same issue here: I have an Ionic app with this plugin which works flawlessly on iOS 9. The same app on iOS 10 crashes on the 5th or 6th scan. When running the app from Xcode on the device, the error message in the output window is:
Looking at the memory consumption, the app starts out with about 35 - 50 MB and on each scan between 20 and 30 MB are added and never freed. When memory usage exceeds 150 MB the next scan reliably crashes the app. I'm not sure how to proceed. Since the bug is only present with iOS 10 beta and not in iOS 9 it might have to be resolved by Apple, not the barcode scanner plugin? |
I don't even get the message from the debugger with my testing. It just crashes the connection and shows nothing. I have however found that the leak of 100 MiB per scan is tied to this line in the -setUpCaptureSession method: I removed that from the plugin and it appears to leak a good amount less than before. The only issue that I am having difficulty with right now is understanding why this is a leak now in iOS 10, and where the 10-15 MiB leak is in the application itself. Removing that line has made it so that it takes about 20-30 scans before I can crash the application. It will only seem to crash after the application leak manages to get to critical mass (highest I've gotten so far in testing is 515 MB). I believe it has something to do with the capture stream from the AVCaptureSession/AVCaptureVideoDataOutput but I just don't understand enough about what I'm looking at/into to really find the correct course. The majority of the leaked memory seems to be dirty IOKit VM allocations that just float there forever. |
It's the same here with an iOS 9.3.5: hope this helps.. |
ok, don't know why, but removing the animation breaks everything again (always after ~30 scan) -> 3d8e3922d8ee79cc5a030c36ee59efb1ea1ac234 I think could be something here (check the differences): phonegap/src/ios/CDVBarcodeScanner.mm - (void)barcodeScanDone:(void (^)(void))callbackBlock {
self.capturing = NO;
[self.captureSession stopRunning];
[self.parentViewController dismissViewControllerAnimated:YES completion:callbackBlock]; telerik/src/ios/CDVBarcodeScanner.mm - (void)barcodeScanDone {
self.capturing = NO;
[self.captureSession stopRunning];
[self.parentViewController dismissViewControllerAnimated: YES completion:nil]; and telerik: - (void)barcodeScanSucceeded:(NSString*)text format:(NSString*)format {
dispatch_sync(dispatch_get_main_queue(), ^{
[self barcodeScanDone];
AudioServicesPlaySystemSound(_soundFileObject);
[self.plugin returnSuccess:text format:format cancelled:FALSE flipped:FALSE callback:self.callback];
});
} phonegap: - (void)barcodeScanSucceeded:(NSString*)text format:(NSString*)format {
dispatch_sync(dispatch_get_main_queue(), ^{
[self barcodeScanDone:^{
[self.plugin returnSuccess:text format:format cancelled:FALSE flipped:FALSE callback:self.callback];
}];
AudioServicesPlaySystemSound(_soundFileObject);
});
} |
I saw no change with what you mentioned here. The difference between the Phonegap and Telerik versions of the scanner is how they perform the barcodeScanDone event. That was the only change I saw between the two. Regardless of that, I was still able to encounter the small memory leak with the scanner. There still appears to be something around a 10 MB allocation that I cannot find and cannot seem to release from some aspect of the AVCaptureSession. The allocation occurs when the AVCaptureSession is started, but doesn't dealloc after stopping the session. It appears to be another smaller IOKit allocation. |
I don't think so that the callback on barcodeScanSucceded is the problem. I think could be a issue of iOS 10 that doesn't release the memory because in iOS 9 it's working fine. We can see at the fallowing link https://forums.developer.apple.com/thread/61620 that other developers have a problem with the AVCaptureSession that it is a class that the library uses. I have another issue with the iphone 4s but with iOS 9.3.5. The issue is the same after a few times the app crash . Has someone had the same problem? |
That forum post is my post regarding this issue. As for the issue appearing on other platforms, I have an ancient iPad (i think first gen) and an iPhone 5c that were running the scanner without issues. It sounds similar to what I'm encountering on iOS 10, although I'm not specifically encountering the issue. The biggest problem so far that I've found is tied to the video output settings. That is what is causing the 100 MiB allocations for IOKit. I was able to verify that by changing to another setting (420YpCbCr8BiPlanarVideoRange and 420YpCbCr8BiPlanarFullRange) for testing sake and seeing that the memory is not being allocated in the same manner. Obviously the scanner doesn't work correctly with different settings, but there still remains a small increase in the application footprint. I'm still investigating this, but time is running out on my end and I'm running out of resources. |
The problem persists with iOS 10 final and plugin version 6.0.2. |
Guys i created a new plugin and i fixed this issue. |
@Mole93 could you submit a PR to the main project to fix the memory leak? Thanks for your work! |
@startupfoundry I can't because i changed completely the core logic of this plugin. |
Based on what I can see from @Mole93's branch and the plugin he cloned, it looks like I might have a working code base to resolve this issue. I'm not entirely sure if it won't provide other issues, because the core of his alternate scanner logic uses an AVCaptureMetadataOutputObjectsDelegate and the underlying metadataOutput structure to replace the AVCaptureVideoDataOutputSampleBufferDelegate and the zxing library to identify the barcodes. If my testing confirms this, I will submit a PR with the alternate methods. |
@jlowe234 awesome. Thanks for your work on this guys! |
Changed delegate to AVCaptureMetadataOutputObjectsDelegate to support AVFoundation's barcode scanner reader without memory leaks from the zxing library & the SampleBuffer delegate.
Changed CDVbcsProcessor to use AVCaptureMetadataOutputDelegate instead of SampleBuffer and zxing to resolve iOS 10 memory leak issue.
Update CDVbcsProcessor for phonegap#312
Hey guys, have a release date the 6.0.3 with this fix? I have the same issue here! |
Update CDVbcsProcessor for phonegap#312
@jlowe234 are you comfortable using your version in a production environment? |
I do feel comfortable with it. I'm awaiting sign off on an update with one of my apps that contains the submitted changes. My testing has been great so far. I believe the only possible issue area is with UPC-A and EAN13 formatting because that has been slightly modified to fit with the new metadata structure. Admittedly, the majority of my app's barcode capabilities are related to QR. |
I still have the same issue with the latest version of this plugin. It happens to the iPhone 6, iOS 10 after the 4th scans. App crashed. I guess I have version 6.0.2 which is not included this fix, right? |
I have the same issue. Works perfectly on iOS 9, but crashes on iOS 10 after opening 3-4 times. iPhone 5S |
I was having the same issue so I initially switched to @Mole93's plugin and it solved the crashing problem but it was very slow in comparison. I then manually copied the RAW contents of the CDVBarcodeScanner.mm file from @jlowe234's pending pull request and replace the contents of It's now working fine. No crashes, no memory leaks. Thanks @jlowe234 & @Mole93! EDIT: Just to add, I can confirm this pull request resolves the memory leak. |
Any plans to include @jlowe234's pull request any time soon? |
Honestly this needs to be merged ASAP. This bug causes crashes for every iOS 10 user (Over 30%+ of iPhones have already updated to 10). |
Not so clean but you can reference a github branch as a plugin, so here's a "do not try this at home" way: inside your <plugin name="phonegap-plugin-barcodescanner" spec="https://github.com/jlowe234/phonegap-plugin-barcodescanner.git#leak#312" /> quick & dirty |
@lesion thanks, you saved me :) |
I took the project that I had from the first post and updated the plugin with the source from my repo. My barcode scans were as follows for the above two codes: Barcode 1 - Barcode 2 - Both codes appear to be correct based on what I could look up on the USPS tracking number format. The prefix is 420 + 5 digits (destination ZIP) plus the displayed numbers under the code. I really can't tell you what could be wrong without seeing a project that can reliably reproduce the issue. Do you have a small project that you can share which will demonstrate your reported issue? |
I use https://github.com/jlowe234/phonegap-plugin-barcodescanner plugin to scan barcode, but I can't scan follow barcode: |
What kind of barcode is that? Does it scan with the existing plugin? I could not get that barcode to scan with my branch of the plugin nor the current version of the plugin. |
jlowe234, Thank you so much! |
Same - I'm anxious for pull request #338 to be merged. There are only a few companies out there who all want $1000s a year for PDF417. When merged, I'm going to find a way send you a $ tip, jlowe234. |
@caixiang2014 this code looks be Codabar type. |
If that is codabar, it is not supported with the ios version of the plug-in. That would be something that you would need to open a separate issue regarding. There are a few other Barcode variants that can be added via the AVMetadata change in my PR but I am unfamiliar with them so I did not add them. |
Hi folks, Thanks a lot for figuring this out and of course a HUGE THANKS to @jlowe234 for his PR which I've just merged and released as part of 6.0.3 🎉 |
The barcode scanner is still crashing for iOS 10 after 4-5 trials of opening/closing the camera. Is anyone else having this issue still? If not, I am testing in Ionic View and haven't tested and compiled to a native app yet, so this may be the issue - but I doubt it. iPhone 5S |
I tested on iPhone 6 with IOS 10.0.2 and I don't see any crashing. I tested after compiling to a native app. |
@osirisr Ionic View is not running the latest barcodescanner plugin version. By its very nature it's lagging behind. |
@EddyVerbruggen Well I use the command It is returning version 6.0.3, which I assume is the same as the version 6.0.3 that's here on Github... Right? @dmgfjaved - I have iOS 10.0.1 ... it could be that this fix only works for iOS 10.0.2+ I'll provide an update once I compile to native app. |
I think the fix is actuallybpart of release 6.0.3. On Sunday, 23 October 2016, osirisr notifications@github.com wrote:
|
@EddyVerbruggen I was unaware that Ionic View does not use the cordova plugin version you have installed in the project. After compiling and running on iOS 10.0.1 iPhone 5S, the barcode camera is no longer crashing! Thank you! |
Issue is still there with 6.0.3 for me. is there a workaround, even temporarily I need to get an update of my app pretty quickly. Many thanks |
you can use my plugin plugin-barcode-ios to fix this issue very quickly |
Thx @Mole93 , that is brilliant I am now using your plugin. It seems that I lost the red line on the capture window . I only got the green square. |
@jaguarg which red line? Do you have any img that you can show me? |
@jaguarg ok, I got it. Can you open the issue on my plugin, please? I'll fix it soon |
done. |
Any update on this issue? I'm still having this issue on iOS 10.1+ |
This thread has been automatically locked. |
There appears to be a memory leak occurring when using the scanner against iOS 10 devices.
I've created the following test case that allocates/deallocates successfully on an iPad with iOS 7.1.2, but will never dealloc the scanner on iOS 10.
Here's the app that I used in my test. Just a standard Cordova (5.3.3) + barcodescanner (6.0.1) with the following index.html.
The text was updated successfully, but these errors were encountered: