Hi,
My app needs to loop though potentially a large number of images for upload, during which I convert to Base64 using the following code:
try
{
using (var stream = file.GetStream())
{
var bytes = new byte[stream.Length];
await stream.ReadAsync(bytes, 0, (int)stream.Length);
var base64Image = Convert.ToBase64String(bytes);
int base64EncodedSize = 4 * bytes.Length / 3;
var sizeInKb = base64EncodedSize / 1000;
Debug.Write($"OPOCDebug {DateTime.Now.ToString("hh:mm:ss.fff")}: ConvertImageAsync MediaFile String Length {sizeInKb}Kb");
return base64Image;
}
}
catch (Exception ex)
{
throw ex;
}
The above is called via a foreach loop on the Image collection and I'm seeing lots of the following in the Debud window which is slowing down the overall process:
09-24 09:52:03.544 I/.telerik.OPOCv(28042): Explicit concurrent copying GC freed 5(79KB) AllocSpace objects, 0(0B) LOS objects, 64% free, 3MB/9MB, paused 192us total 29.213ms
I've read the follwiong post:
https://markolazic.com/prevent-xamarin-forms-signaturepad-memory-leak-android/
...which states: "Every garbage collection (explicit or not) has performance implications, because it blocks all the threads until finished." Can any one suggest how I refactor the above to prevent the need for GC or any alternative on how to perform the requirements?
Thanks in advance.