I have a WPF window with a list of documents(DataGrid) (from an sql VarBinary(Max) field binding
on click of list item, I load the datafiled into a Memoystream like:
public MemoryStream docStream = new()
docStream
= new MemoryStream(dt.Rows[0].Field<byte[]>("Document"))
In the WPF MainWindow i have a ContentControl where I place via code a UserControl that only has a PDFViewer, then I load the memorystream into the PdfViewer like this:
ucPdfView.Instance.myPdfViewer.Load(docStream);
when a user clicks on other documents in list it wil reload the new sql datafiled into the Memorystream etc...
This all works well..
but while navigating and previewing documents, the memory usage keeps going up until I get an out of memory error.... even if you just keep clicking on same item in list over and over..
I cant find a way to release this memory
If I follow same steps as above but just omit the asising the DocStream to the pdfviewer (no pdf preview showm just the blank pdfviewer, but I do fill the MemoryStream
docStream
) i have no problems with memory usage...
Im not using MVVM in this app.... could you provide a sample of an optimized way to achive this correctly?