[
  {
    "Id": "273620",
    "ThreadId": "79867",
    "Html": "<p>I have a project where I am zipping lots of files continuously. However quite quickly the program starts using alot of memory (got up to 600mb after a couple of mins. The larger the files that it zips, the more quickly the memory is being used up. I am watching the memory use through Windows Task Manager on XP. I am using version 1.9.0.31of the library.</p>\r\n<p>I am using the following code:</p>\r\n<div style=\"color:Black;background-color:White\">\r\n<pre><span style=\"color:Blue\">Using</span> zip <span style=\"color:Blue\">As</span> ZipFile = <span style=\"color:Blue\">New</span> ZipFile\r\n  zip.MaxOutputSegmentSize = 20 * 1024 * 1024   <span style=\"color:Green\">'' 20mb</span>\r\n  zip.Encryption = EncryptionAlgorithm.None\r\n  zip.CompressionLevel = Ionic.Zlib.CompressionLevel.BestCompression\r\n  zip.AddFile(locationOfFileToZip)\r\n  zip.Save(fileLocation)\r\n  zip.Dispose()\r\n<span style=\"color:Blue\">End</span> <span style=\"color:Blue\">Using</span>\r\n\r\n</pre>\r\n</div>\r\n<p>Not sure if i am missing something, or need to clear anything out or do any rubbish collecting ??</p>\r\n<p>Thanks All !</p>\r\n<p>&nbsp;</p>\r\n<p>&nbsp;</p>",
    "PostedDate": "2010-01-05T21:25:44-08:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "273695",
    "ThreadId": "79867",
    "Html": "<p>You don't need to do any rubbish collecting.</p>\r\n<p>You also don't need to call zip.Dispose() if you are using a Using clause.</p>\r\n<p>Does the memory usage never stop increasing?&nbsp;</p>\r\n<p>If you zip large files, DotNetZip will allocate large buffers.&nbsp;&nbsp; This is normal.&nbsp; Often the .NET garbage collector will not GC the unused buffers until there is memory pressure.&nbsp; In some cases people incorrectly conclude this indicates a memory leak.&nbsp; Large memory usage, even 600mb, does not necessarily indicate a memory leak.&nbsp;</p>\r\n<p>Evidence of a memory leak is consistent memory growth, with every iteration.&nbsp; Is that what you are seeing?&nbsp; How many bytes does the memory usage grow, for each iteration?&nbsp;</p>\r\n<p>&nbsp;</p>",
    "PostedDate": "2010-01-06T02:20:59.35-08:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "279308",
    "ThreadId": "79867",
    "Html": "<p>I am seeing the same thing.&nbsp; I have the version 1.9.1.1.&nbsp; It appears that there is something in the Save() that is increasing my memory roughly the same size as the zip file that is written to the disk.&nbsp; I have tried to call dispose as well as calling the GC but nothing appears to shrink remove the memory it grows every time I save a zip file.&nbsp; I looked at the ZipFile source, however, I was not able to find the issue.&nbsp; Like JBGillet said, it becomes a problem when you create large amounts of zip files.&nbsp; I guess you start to notice the memory usage. Here is a sample code to reproduce this issue.</p>\r\n<p>&nbsp;</p>\r\n<p>\r\n<div style=\"color:Black;background-color:White\">\r\n<pre>        <span style=\"color:Blue\">private</span> <span style=\"color:Blue\">void</span> makeZipFile(<span style=\"color:Blue\">string</span> zipFile, <span style=\"color:Blue\">string</span>[] filePaths, <span style=\"color:Blue\">string</span> comment)\r\n        {\r\n\r\n            <span style=\"color:Blue\">using</span> (ZipFile zip = <span style=\"color:Blue\">new</span> ZipFile())\r\n            {\r\n                zip.CompressionLevel = CompressionLevel.BestCompression;\r\n                <span style=\"color:Blue\">foreach</span> (<span style=\"color:Blue\">string</span> fileName <span style=\"color:Blue\">in</span> filePaths){\r\n                    zip.AddFile(fileName,<span style=\"color:#A31515\">&quot;&quot;</span>);\r\n                }\r\n                zip.Comment = comment;\r\n                zip.Save(zipFile);\r\n                zip.Dispose();\r\n            }\r\n        }\r\n<br></pre>\r\n</div>\r\n</p>\r\n<p>&nbsp;</p>",
    "PostedDate": "2010-01-19T22:00:43.68-08:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "279518",
    "ThreadId": "79867",
    "Html": "<p>First, your call to ZipFile.Dispose() is unnecessary, as it is called implicitly when the using scope exits.</p>\r\n<p>Second, I did some analysis work.</p>\r\n<p>I grabbed ionic.Zip.dll v1.9.1.1, and ran your code (removing the call to Dispose())&nbsp; in a simple loop, of 1024 iterations.&nbsp; In other words it produces a zip file 1024 times in a loop.&nbsp; As input for the zip file, I used a set of 128 C# sourcecode files.&nbsp;&nbsp;&nbsp;The output zipfile used the same name, for every iteration.&nbsp;After each set of 16 iterations, I did an analysis of the .NET heap and of the working set of the process.&nbsp; What I found was steady-state.&nbsp; There was&nbsp;no increase in the size of the working set of the process, or in the size of the &nbsp;.NET heap, with each successive 16 iterations.</p>\r\n<p>If there had been a memory leak, I would expect to see growth in the .NET heap, or in the private bytes used by the process.&nbsp; But I saw no growth.&nbsp;</p>\r\n<p>To do this analysis, I used the WinDbg.exe tool, part of the <a href=\"http://www.microsoft.com/whdc/devtools/debugging/default.mspx\">Debugging Tools for Windows</a>.&nbsp; I followed <a href=\"http://blogs.msdn.com/tess/archive/2006/01/23/net-memory-leak-case-study-the-event-handlers-that-made-the-memory-baloon.aspx\">the recommendations of the Microsoft .NET Servicing engineers, regarding how to analyze memory leaks in .NET processes</a>.&nbsp; Specifically I used the !eeheap -gc and !dumpheap -stat commands, available&nbsp;from sos.dll.&nbsp;</p>\r\n<p>An excerpt of what I found is here:</p>\r\n<pre>Cycle 1:\r\n\r\nPDB symbol for mscorwks.dll not loaded\r\nNumber of GC Heaps: 1\r\ngeneration 0 starts at 0x01c21018\r\ngeneration 1 starts at 0x01c2100c\r\ngeneration 2 starts at 0x01c21000\r\nephemeral segment allocation context: none\r\n segment    begin allocated     size\r\n01c20000 01c21000  01cb7ff4 0x00096ff4(618484)\r\nLarge object heap starts at 0x02c21000\r\n segment    begin allocated     size\r\n02c20000 02c21000  02c24260 0x00003260(12896)\r\nTotal Size   0x9a254(631380)\r\n------------------------------\r\nGC Heap Size   0x9a254(631380)\r\n\r\n\r\n\r\nCycle 2:\r\n\r\n:000&gt; !eeheap -gc\r\nNumber of GC Heaps: 1\r\ngeneration 0 starts at 0x01d058a8\r\ngeneration 1 starts at 0x01c8d4b8\r\ngeneration 2 starts at 0x01c21000\r\nephemeral segment allocation context: none\r\n segment    begin allocated     size\r\n01c20000 01c21000  01e5c988 0x0023b988(2341256)\r\nLarge object heap starts at 0x02c21000\r\n segment    begin allocated     size\r\n02c20000 02c21000  02c25260 0x00004260(16992)\r\nTotal Size  0x23fbe8(2358248)\r\n------------------------------\r\nGC Heap Size  0x23fbe8(2358248)\r\n\r\n\r\nCycle 3:\r\n\r\nNumber of GC Heaps: 1\r\ngeneration 0 starts at 0x01cd7d88\r\ngeneration 1 starts at 0x01c5f998\r\ngeneration 2 starts at 0x01c21000\r\nephemeral segment allocation context: none\r\n segment    begin allocated     size\r\n01c20000 01c21000  01e2ee68 0x0020de68(2154088)\r\nLarge object heap starts at 0x02c21000\r\n segment    begin allocated     size\r\n02c20000 02c21000  02c25260 0x00004260(16992)\r\nTotal Size  0x2120c8(2171080)\r\n------------------------------\r\nGC Heap Size  0x2120c8(2171080)\r\n\r\n\r\ncycle 4:\r\n\r\nNumber of GC Heaps: 1\r\ngeneration 0 starts at 0x01ceeb18\r\ngeneration 1 starts at 0x01c76728\r\ngeneration 2 starts at 0x01c21000\r\nephemeral segment allocation context: none\r\n segment    begin allocated     size\r\n01c20000 01c21000  01e45bf8 0x00224bf8(2247672)\r\nLarge object heap starts at 0x02c21000\r\n segment    begin allocated     size\r\n02c20000 02c21000  02c25260 0x00004260(16992)\r\nTotal Size  0x228e58(2264664)\r\n------------------------------\r\nGC Heap Size  0x228e58(2264664)\r\n\r\nCycle 5:\r\n\r\nNumber of GC Heaps: 1\r\ngeneration 0 starts at 0x01d058a8\r\ngeneration 1 starts at 0x01c8d4b8\r\ngeneration 2 starts at 0x01c21000\r\nephemeral segment allocation context: none\r\n segment    begin allocated     size\r\n01c20000 01c21000  01e5c988 0x0023b988(2341256)\r\nLarge object heap starts at 0x02c21000\r\n segment    begin allocated     size\r\n02c20000 02c21000  02c25260 0x00004260(16992)\r\nTotal Size  0x23fbe8(2358248)\r\n------------------------------\r\nGC Heap Size  0x23fbe8(2358248)\r\n\r\n</pre>\r\n<p>As you can see there is no net growth in th GC heap size, as there would be if a memory leak were present in the DotNetZip code.&nbsp; The !dumpheap output showed similarly steady results, indicating no net growth.&nbsp;</p>\r\n<p>I also used the Perfmon tool and monitored the &quot;Private Bytes&quot; counter for my process, as it ran.&nbsp; It produced an absolutely flat line for memory size, which you can see here:&nbsp;</p>\r\n<p><img src=\"http://i46.tinypic.com/34gldaq.jpg\" alt=\"\"></p>\r\n<p>If you could provide some additional information as to how you are determining that a leak is occurring, I'd be happy to look into this further.&nbsp; Maybe you are using a larger number of files?&nbsp; Maybe you are using a larger number of iterations, beyond 1024.&nbsp; You said &quot;a large number of zip files&quot; but gave no specifics.&nbsp; &nbsp; If you have a more complete code snip that shows exactly how you reproduce the leak, that would be helpful.&nbsp; Maybe you are trying to compress binary files? or a mixture of files?&nbsp; Or files above a certain size?&nbsp; What tools, specifically, are you using that lead you to conclude that a memory leak is present?&nbsp; If you can show me output from Windbg.exe, or Perfmon,&nbsp;that would really help.</p>\r\n<p>It's possible there is no leak.&nbsp; In some cases people observe a .NET process and see an initial&nbsp;growth in memory and conclude it is a leak.&nbsp; But in a managed-memory environment, such as that provided by .NET, there will be a large growth in memory usage as each class is instantiated.&nbsp; PRocesses &quot;warm up&quot;.&nbsp; The definitive evidence of a leak is when the memory usage grows steadily, with each iteration.&nbsp; This is what I have not seen.&nbsp;</p>\r\n<p>&nbsp;</p>",
    "PostedDate": "2010-01-20T07:59:03.097-08:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "279595",
    "ThreadId": "79867",
    "Html": "<p>I noticed the same thing.</p>\r\n<p>Some details first. I use the Ionic.Zlib namespace only to compress messages between systems (through hooking into WCF). I 'm compressing messages of various sizes between a few KBs and hundreds of MBs. Before I was using the DeflateStream, but then i switched only the compressing stream to ParallelDefalteOutputStream and i noticed the memory leak. To verify i switched back to DeflateStream and the leak was gone.</p>\r\n<p>&nbsp;</p>",
    "PostedDate": "2010-01-20T10:14:00.807-08:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "279607",
    "ThreadId": "79867",
    "Html": "<p>ok, that's good information, worth exploring. I'll look into it and respond here.</p>",
    "PostedDate": "2010-01-20T10:30:16.43-08:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "279629",
    "ThreadId": "79867",
    "Html": "This discussion has been copied to a work item. Click <a href=\"http://dotnetzip.codeplex.com/WorkItem/View.aspx?WorkItemId=10030\">here</a> to go to the work item and continue the discussion.",
    "PostedDate": "2010-01-20T11:10:56.313-08:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "279644",
    "ThreadId": "79867",
    "Html": "<p>OK, there's definitely a leak.&nbsp; The ParallelDeflateOutputStream is not being GC'd and all of the buffers maintained by that thing remain in memory.</p>\r\n<p>&nbsp;</p>",
    "PostedDate": "2010-01-20T11:41:06.247-08:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "279737",
    "ThreadId": "79867",
    "Html": "<p>I updated the test case I had, so that it uses the ParallelDeflateOutputStream.&nbsp; The test case is still very simple. It just creates&nbsp;a zip file, many times in a row.&nbsp; Here's the perfmon trace for my updated test case, using the v1.9.1.1 bits:</p>\r\n<p><img src=\"http://i48.tinypic.com/ju8eg7.jpg\" alt=\"\"></p>\r\n<p>You can see that clearly illustrates the leak.</p>\r\n<p>Here's the trace for the test case, using the v1.9.1.2 bits, which includes the fix to workitem 10030:</p>\r\n<p><img src=\"http://i47.tinypic.com/2dw5dvn.jpg\" alt=\"\"></p>\r\n<p>Thanks for reporting this.</p>\r\n<p>v1.9.1.2 will be available shortly.</p>",
    "PostedDate": "2010-01-20T14:27:13.9-08:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "279868",
    "ThreadId": "79867",
    "Html": "<p>v1.9.1.2 is now available.&nbsp; It includes the fix for this leak.</p>\r\n<p>Thanks for reporting it.</p>\r\n<p>&nbsp;</p>",
    "PostedDate": "2010-01-20T22:11:24.047-08:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "280150",
    "ThreadId": "79867",
    "Html": "Thanks so much!  I will check it out tonight.<br><br>On 1/21/10, Cheeso &lt;notifications@codeplex.com&gt; wrote:<br>&gt; From: Cheeso<br>&gt;<br>&gt; v1.9.1.2 is now available.  It includes the fix for this leak.Thanks for<br>&gt; reporting it.<br>&gt;<br>&gt; <br><br>-- <br>Sent from my mobile device",
    "PostedDate": "2010-01-21T10:21:30.087-08:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "280153",
    "ThreadId": "79867",
    "Html": "<p>doops, I'll be interested to hear of your results.</p>\r\n<p>&nbsp;</p>",
    "PostedDate": "2010-01-21T10:23:43.813-08:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "280677",
    "ThreadId": "79867",
    "Html": "The new release works like a charm.  There memory is staying just as I would expect it to.  Great work!  Thanks for getting that done for me.<br><br><div>On Thu, Jan 21, 2010 at 12:23 PM, Cheeso <span dir=ltr>&lt;<a href=\"mailto:notifications@codeplex.com\">notifications@codeplex.com</a>&gt;</span> wrote:<br>\r\n<blockquote style=\"margin:0pt 0pt 0pt 0.8ex;padding-left:1ex\">   <div> <p>From: Cheeso</p> <div><p>doops, I'll be interested to hear of your results.</p>\r\n\r\n<p> </p></div> <div><div> <p>Read the <a href=\"http://dotnetzip.codeplex.com/Thread/View.aspx?ThreadId=79867&ANCHOR#Post280153\">full discussion online</a>.</p> <p>To add a post to this discussion, reply to this email (<a href=\"mailto:DotNetZip@discussions.codeplex.com?subject=[DotNetZip:79867]\">DotNetZip@discussions.codeplex.com</a>)</p>\r\n <p>To start a new discussion for this project, email <a href=\"mailto:DotNetZip@discussions.codeplex.com\">DotNetZip@discussions.codeplex.com</a></p> </div><p>You are receiving this email because you subscribed to this discussion on CodePlex. You can <a href=\"http://www.codeplex.com/site/discussions/thread/unsubscribe/79867\">unsubscribe</a> on CodePlex.com.</p>\r\n <p>Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at CodePlex.com</p> </div> </div> </blockquote></div><br>",
    "PostedDate": "2010-01-22T10:49:47.853-08:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  }
]