This project is read-only.

Memory usage

Oct 1, 2010 at 10:37 AM


I'm using Sevenzipsharp in a business application, it's working quite OK, but sometimes there is an issue with very high memory usage.

For example, when the application uses sevenzipsharp to compress 29 files with a total size of 21 MB, sevenzipsharp uses over 250 MB of memory. Is this normal?

Is it more memoryefficient to compress only one file to begin with, and then add the other files to the archive successively?

Oct 1, 2010 at 8:54 PM


I suppose you create 7-Zip archives, right? 7-Zip compression algorithm takes from 2mb up to 2-4gb of memory. the actual amount depends of the compression rate - from Fast to Ultra, respectively. "Normal" consumes about 256mb. But don't worry: the actual value of USED memory is hundreds of times smaller, as algorithm just reserves the theretically required space. Only if you compress 4 gigs of stuff on Ultra, several gigs of operating memory will be really used.

My words can be proved by Windows Task Manager memory monitor. It shows the actual amount of used physical memory (not virtual), and the graph shows no sharp jumps after some compression job is started. Well, if you measure memory consumption with Task Manager and do get a 250mb fluctuation, it is embarrasing and shouldn't be at all. Contact me in that case.

The nasty thing is that if 7-Zip can't reserve the required space, it will fail, so you should catch the corresponding error code in CheckedExecute() at Common.cs, which then is rethrown as a general exception. I will conduct experiments with memory reservation and add the corresponding OutOfMemory exception in the next release. At the moment, you can't check why compression failed - will it be a lack of free memory or any other issue. 

Oct 5, 2010 at 1:39 PM


Thanks for the quick reply. Yes, I create 7-Zip archives. I changed my compressionlevel to "Fast", and now it practically consumes/reserves no memory at all.

Like you said, if 7-Zip can't reserve the memory it wants, it will crash. Therefore, if your application is already close to the ~1.4 GB limit (on x86), it will crash even though it doesn't actually need to.

And I believe you are wrong about Windows Task Manager now showing the memory allocated by 7-Zip. Personally I use ANTS Memory Profiler for my memory profiling since Windows Task Manager is highly unreliable at its best, but both of them showed a clear diffrence in memoryusage when zipping at Normal(default) compression vs. Fast compression. In my testcases the difference was about 300 MB.