-2

I use ionic zip (version-1.9.1.8) to compress some files..I usually have large files summing to 2 to 3 GB ...this ionic zip works fine in my system but while i use it in another user machine(ONSITE)...this ionic zip throws an exception as follows.The configuration of both the system are same.

Exception details:
******************
[6/11/2012 01:21:38:812]
 System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.
   at Ionic.Zip.ZipEntry._WriteEntryData(Stream s)
   at Ionic.Zip.ZipEntry.Write(Stream s)
   at Ionic.Zip.ZipFile.Save()
   at Ionic.Zip.ZipFile.Save(String fileName)
   at MyCode.SaveZipFile()

[6/11/2012 01:21:38:828]

System.NullReferenceException: Object reference not set to an instance of an object.
   at Ionic.Zlib.ParallelDeflateOutputStream._Flush(Boolean lastInput)
   at Ionic.Zlib.ParallelDeflateOutputStream.Close()
   at Ionic.Zlib.ParallelDeflateOutputStream.Dispose()
   at Ionic.Zip.ZipFile.Dispose(Boolean disposeManagedResources)
   at Ionic.Zip.ZipFile.Dispose()
   at Mycode.SaveZipFile()
   at Mycode.SaveLogs()

Could someone help me to find the cause of such issues..??

Thanks in advance

Druid
  • 6,423
  • 4
  • 41
  • 56
Techy
  • 315
  • 1
  • 5
  • 14
  • Add more memory? :) `'System.OutOfMemoryException'` is pretty serious. So you either need to avoid it or use another, more efficient, zip decoder instead of iconic.zip. How about SharpDevlops Zip? – iCollect.it Ltd Jun 11 '12 at 11:06
  • I cannot afford to go for another zip tool...Something has to be there to fix this issue right since i dont face this memory problem in my system .. – Techy Jun 11 '12 at 11:14
  • Stupid question: Does *your system* have more memory than the one that crashes? – iCollect.it Ltd Jun 11 '12 at 11:24
  • 4
    *Configuration* does not necessarily mean memory. "May be I suggest you to" be a little politer when asking everyone else to solve *your* problems... :) I will take my advice elsewhere now. – iCollect.it Ltd Jun 11 '12 at 12:52

1 Answers1

4

You need to show the code. If your app is zipping into a memorystream, it will be susceptible to out-of-memory conditions. This would be a problem in your app, not in the library.

Also - I see from the stacktrace that it is using the parallel deflater. This trades runtime for memory. IF you have memory issues, you can disable parallel compression, and use much less memory.

Do this by something like this in your code:

 zip.ParallelDeflateThreshold = -1;

also see the doc on this feature: http://cheeso.members.winisp.net/DotNetZipHelp/html/0988edb5-1d59-2875-8e77-ad195601cbce.htm

Cheeso
  • 189,189
  • 101
  • 473
  • 713
  • Thanks cheeso..i understand the use of ParallelDeflateThreshold ..In the link you provided it states that "The default value for this property is -1, which means parallel compression will not be performed unless you set it to zero." So should i set this property to zero and check it out..Also what is the default compression method used by ionic zip... – Techy Jun 15 '12 at 06:39
  • Default compression is DEFLATE. Try it with the threshold set explicitly to -1. Not sure that is actually the default. Try and see. – Cheeso Jun 15 '12 at 07:51
  • i have set the threshhold to -1 and then too i resulted with an exception,the only difference is that this exception happens after a while..i have read in another article regarding the use of zipoutputstream...should i be using that instead of zipfile class..and to make note that i try to zip files greater than 2GB – Techy Jun 15 '12 at 08:42
  • Well I don't know what your code looks like, so it's hard to say. It's possible to use the library in a way that would lead to an out of memory error, and a simple optimization of the usage would avoid the problem. But I cannot say if that is the case, because I have not seen your code. Switching to ZipOutputStream will not use significantly less memory, for properly structured code. You should use the class that you feel most comfortable with. When streaming, it's possible that you will think the zipoutputstream is a more natural choice. – Cheeso Jun 15 '12 at 08:45
  • Thanks cheeso for your time..I have a huge code here so i have just added the zip file scope in my project ..This is how it goes.. this._zip.AddEntry(archieveDir, streamReader.ReadToEnd()); this._zip.AddEntry(archieveDir, FileStream); this._zip.Save(this._zipFilePath); ->This throws the exception..And note that the filestream has large number of files of more than 1.5 GB – Techy Jun 15 '12 at 08:54
  • If I had to guess, I'd suppose there are some opportunities for improvement in your code. But I cannot say for sure. You would need to post the actual stacktrace you receive, and your actual code. 3 lines of pseudo code won't help a diagnosis. – Cheeso Jun 15 '12 at 08:57