You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Using xamarin forms, I've implemented a custom renderer to show a camera preview in a tabbed page (snapchat like). When moving away from the page and back (a few times) I get a out of memory exception.
When the page is appearing the following gets called:
try
{
Console.WriteLine("OPENING");
var watch = System.Diagnostics.Stopwatch.StartNew();
camera = Camera.Open(0);
camera.SetDisplayOrientation(90);
var parameters = camera.GetParameters();
var bitsPerPixel = Android.Graphics.ImageFormat.GetBitsPerPixel(parameters.PreviewFormat);
int bufferSize = (parameters.PreviewSize.Width * parameters.PreviewSize.Height * bitsPerPixel) / 8;
for (uint i = 0; i < 4; ++i)
{
using (FastJavaByteArray buffer = new FastJavaByteArray(bufferSize))
{
// allocate new Java byte arrays for Android to use for preview frames
camera.AddCallbackBuffer(new FastJavaByteArray(bufferSize));
}
// The using block automatically calls Dispose() on the buffer, which is safe
// because it does not automaticaly destroy the Java byte array. It only releases
// our JNI reference to that array; the Android Camera (in Java land) still
// has its own reference to the array.
}
watch.Stop();
System.Diagnostics.Debug.WriteLine("Opening camera: {0}ms", watch.ElapsedMilliseconds);
}
@Vandersteen probably this object is being created twice and not being disposed. This was pointed out on another issue here.
using (FastJavaByteArray buffer = new FastJavaByteArray(bufferSize))
{
// allocate new Java byte arrays for Android to use for preview frames
camera.AddCallbackBuffer(new FastJavaByteArray(bufferSize));
}
Try this:
using (FastJavaByteArray buffer = new FastJavaByteArray(bufferSize))
{
// allocate new Java byte arrays for Android to use for preview frames
camera.AddCallbackBuffer(buffer);
}
Using xamarin forms, I've implemented a custom renderer to show a camera preview in a tabbed page (snapchat like). When moving away from the page and back (a few times) I get a out of memory exception.
When the page is appearing the following gets called:
When the page dissappears:
The previewCallback:
Logs:
Am I missing something ?
Xamarin.Forms: 2.3.4
The text was updated successfully, but these errors were encountered: