Note: This has already been discussed in "http://stackoverflow.com/questions/3819564/reading-from-packagepart-stream-does-not-release-memory" which resulted in the conclusion that maybe the Package has an internal caching feature. Can this be confirmed?
Or is the cause something else?
In our application, we are reading an XPS file using the System.IO.Packaging.Package class. When we read from a stream of a PackagePart, we can see from the Task Manager that the application's memory consumption rises. However, when the reading is done,
the memory consumption doesn't fall back to what it was before reading from the stream.
To illustrate the problem, I wrote a simple code sample that you can use in a stand alone wpf application.
public partial class Window1 : Window
_package = Package.Open(@"c:\test\1000pages.xps", FileMode.Open, FileAccess.ReadWrite, FileShare.None);
private void ReadPackage()
foreach (PackagePart part in _package.GetParts())
using (Stream partStream = part.GetStream())
byte arr = new byte[partStream.Length];
partStream.Read(arr, 0, (int)partStream.Length);
private void Button_Click(object sender, RoutedEventArgs e)
View Complete Post