Bug 22142 - Camera SetPreviewCallback and SetPreviewCallbackWithBuffer causing constant GC collections and freezes
Summary: Camera SetPreviewCallback and SetPreviewCallbackWithBuffer causing constant G...
Alias: None
Product: Android
Classification: Xamarin
Component: General ()
Version: 4.16.0
Hardware: All All
: Normal normal
Target Milestone: ---
Assignee: Jonathan Pryor
Depends on:
Reported: 2014-08-16 17:44 UTC by Jérémie Di Prizio
Modified: 2017-06-27 19:16 UTC (History)
4 users (show)

Is this bug a regression?: ---
Last known good build:

Repro project (12.97 KB, application/x-zip-compressed)
2014-08-16 17:44 UTC, Jérémie Di Prizio

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Jérémie Di Prizio 2014-08-16 17:44:04 UTC
Created attachment 7703 [details]
Repro project

When attempting to get data from hardware Camera preview frame using Camera.IPreviewCallback handler and eihter SetPreviewCallback or SetPreviewCallbackWithBuffer, the image data byte buffer seem to be initiated in memory on each callback generating a lot of strain on the GC, resulting in regular GC collections and subsequently freezes in the application.

Both using SetPreviewCallback and using our own buffer with SetPreviewCallbackWithBuffer cause this GC issue. In fact, this problem has been discussed here: http://forums.xamarin.com/discussion/6114/camera-addcallbackbuffer-causes-rapid-gcs-in-dalvik-is-there-a-way-around-this

Proposed solutions include either doing it yourself in Java (which you'll admit voids the entire purpose of Xamarin Android), or using a clever but unsafe and complicated trick that is not guaranteed to work in future revisions of Xamarin. Both solutions seem subpar and in my opinion you should provide a way to read that preview buffer with minimal GC overhead (avoiding any copy would be best though I understand that's complicated; though iOS implementation of similar feature allow direct access to IntPtr byte array which yields excellent results).

I've include a repro project to illustrate this issue.
Comment 1 Parmendra Kumar 2014-11-03 09:27:00 UTC
I have checked this issue with given sample project. Could you Please checked the screencast and let me know If you also have getting same behavior, Or I have missed anything.

IDE Log:https://gist.github.com/Parmendrak/c13f0f33f42c9c2a768d
Build Log:https://gist.github.com/Parmendrak/778ccd580d9b7a2aeeda

Environment Info:
Xamarin Studio->Version 5.5.3 (build 6)
Xamarin.Android->Version: 4.18.1 (Business Edition)
Mac OS X 10.9.4
Comment 2 Chris Hardy [MSFT] 2017-06-27 19:16:28 UTC
Because we have not received a reply to our request for more information we are closing this issue. If you are still encountering this issue, please reopen the ticket with the requested information. Thanks!