我使用c#创建了windows store app。我正在使用pdfdocument类创建图像格式pdf并在图像中显示。 点击按钮我删除对象并调用垃圾收集器 处理完所有对象后,为什么不释放内存?
doc = await PdfDocument.LoadFromFileAsync(file);
if (doc != null)
{
for (int i = 0; i < doc.PageCount; i++)
{
PdfPage pdf_page = doc.GetPage((uint)i);
IRandomAccessStream randomStream = new InMemoryRandomAccessStream();
await pdf_page.RenderToStreamAsync(randomStream);
MyImage = new WriteableBitmap((int)pdf_page.Size.Width,(int)pdf_page.Size.Height);
await MyImage.SetSourceAsync(randomStream);
await randomStream.FlushAsync();
randomStream.Dispose();
pdf_page.Dispose();
Image img1=new Image();
img1.Source=MyImage;
imggrid.Items.Add(img1);
}
}
private void btnunload_click(object sender, RoutedEventArgs e)
{
imggrid.Items.Clear();
doc = null;
folder = null;
file = null;
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
}
答案 0 :(得分:0)
您可以使用任何Memory Profiler应用程序找到内存泄漏,例如' Sci Tech .NET Memory Profiler ',...