Version 2.5.199
Windows 7, 64-bit
blah blah blah
I use Memory Streams in my application because I do not want anything written to disk. Many of my documents will contain VISA numbers and as such, I do not want to have little baby VISA numbers ever found on deleted parts of the disk or ...
When using Save Document and indicating that I want the file saved to a Stream, I will pass a Memory Stream instead of a File Stream. Again, I do not want to persist to disk rather I want it to go to memory. If I wanted to save the PDF to disk I would have just called SaveDocument giving it a File Path.
By changing the stream type, a memory leak will be created. The code below is from your Full Demo program with a slight change - I added a For/Next loop to show the memory leak quicker and I change the FileStream to a MemoryStream:
Code: Select all
private void b_saveStream_Click(object sender, EventArgs e)
{
string SaveTo = "";
if (DialogResult.OK == saveFileDialog1.ShowDialog(this))
{
SaveTo = saveFileDialog1.FileName;
}
if (SaveTo == "")
return;
int nFlags = 0;
if (cb_OpenWithoutUI.Checked)
nFlags = (int)PDFXCviewAxLib.PXCVA_Flags.PXCVA_NoUI;
object vDataIn = "";
object[] vArr = new object[2];
for (int i = 0; i < 10; i++) // ADDED
{ // ADDED
// FileStream writeStream = new FileStream(SaveTo, FileMode.Create); // COMMENTED
MemoryStream writeStream = new MemoryStream(); // ADDED
IStreamWrapper istr = new IStreamWrapper(writeStream);
object varg1 = g_nActiveDocID;
object varg2 = istr;
vArr[0] = varg1;
vArr[1] = varg2;
vDataIn = vArr;
object OutPar;
try
{
axCoPDFXCview1.DoVerb(null, "SaveDocument", vDataIn, out OutPar, nFlags);
}
catch (Exception ex)
{
ShowErrorMessage(System.Runtime.InteropServices.Marshal.GetHRForException(ex));
}
writeStream.Close();
} // ADDED
}
So, the question is this, I can't use File Streams because I need to keep the file off the disk, how do I do this?
Thanks.