I am using this function which convert thy byte array to image but when this function calls the memory usage of system increasing.This function can be called around 500 times.I tried to dispose or flush to make memory empty but usage still getting increases.I am attaching a task manager image which is showing memory usage.
public static BitmapImage ConvertToBitmapImage(byte[] imageData)
{
if (imageData == null || imageData.Length == 0) return null;
var image = new BitmapImage();
using (var mem = new MemoryStream(imageData))
{
mem.Position = 0;
image.BeginInit();
image.CreateOptions = BitmapCreateOptions.PreservePixelFormat;
image.CacheOption = BitmapCacheOption.OnLoad;
image.UriSource = null;
image.StreamSource = mem;
image.EndInit();
mem.Flush();
mem.Dispose();
}
image.Freeze();
return image;
}