I am trying to debug an OutOfMemoryException
that occurs when creating a fairly large ZIP
file using System.IO.Packaging.ZipPackage
.
The code is iterating through a large list of objects, doing the following for each object.
PackagePart
for the file.System.IO.Stream
to another:
FileStream
PackagePart::GetStream()
=> MS.Internal.IO.Zip.ZipIOModeEnforcingStream
Finally it calls Package::Close()
which saves the file.
The problem I am having is that for a particularly large list of objects, I am seeing an OutOfMemoryException
(the x86 process size is getting to about 1.2GB in size).
I was thinking about partitioning the object data into chunks so I only process a smaller amount per loop (i.e. steps 1-3 above). The idea is that I would create n
ZIP files in a temporary directory, and then find a way to combine them into a single archive.
Is this possible using System.IO.Packaging
? What would I use to combine the parts?
Or is there a better way to fix this?
Calling the Flush
method on the Package object in between creating a new package should probably solve the problem as that would cause the memory buffer to be flushed to disk.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With