C# IIS express中未释放内存使用情况
我正试图用下面的代码解压一个文件C# IIS express中未释放内存使用情况,c#,memory-leaks,zip,iis-express,C#,Memory Leaks,Zip,Iis Express,我正试图用下面的代码解压一个文件 public static void UnZip(string zipFile, string folderPath) { using (ZipArchive zip = new ZipArchive()) { //Loads the zip file. zip.Open(Path.GetFullPath(zipFile)); //Saving the contents of zip fi
public static void UnZip(string zipFile, string folderPath)
{
using (ZipArchive zip = new ZipArchive())
{
//Loads the zip file.
zip.Open(Path.GetFullPath(zipFile));
//Saving the contents of zip file to disk.
for (int i = 0; i < zip.Count; i++)
{
using (ZipArchiveItem item = zip[i])
{
if (!Directory.Exists(folderPath))
Directory.CreateDirectory(folderPath);
string itemName = folderPath + item.ItemName;
using (FileStream fs = new FileStream(itemName, FileMode.OpenOrCreate,
FileAccess.ReadWrite))
{
MemoryStream ms = item.DataStream as MemoryStream;
ms.WriteTo(fs);
fs.Flush();
ms.Close();
}
}
}
zip.Close();
}
}
publicstaticvoid解压(stringzipfile,stringfolderpath)
{
使用(ZipArchive zip=new ZipArchive())
{
//加载zip文件。
zip.Open(Path.GetFullPath(zipFile));
//将zip文件的内容保存到磁盘。
for(int i=0;i
我的问题:
我已经发布了我的web项目,并托管在IIS Express-8中。调用此UnZip
方法时,内存使用量超过600MB
,并且从方法中出来超过一小时后,它不会下降。因此,如果我再次调用相同的方法,我会得到memoryoutofeception
错误,因为默认情况下iis express有800MB
,所以我会得到错误
我不想增加IIS Express的内存大小。可能是我在代码中犯了一些错误,但我找不到问题
帮助我找到问题并解决问题。我会在using block中放入“zip.Close();”当您在
中使用将调用Dispose()的块初始化fs
时,调用fs.Dispose()
是没有意义的
自动为您完成。用using Block包装您的MemoryStream我在这种情况下也尝试过……但不起作用@SiveAjetw为什么您不直接打电话代替所有这些手工劳动?如果您提到。。。在不知道它是什么库的情况下,帮助您将有点棘手。在4.5版本之前,向.NET添加zip支持的最流行的库是(它提供了ZipInputStream
,允许在不首先将内容全部加载到内存的情况下对内容进行流式处理),但显然这不是SharpZipLib。对不起,我在问题中键入了错误。现在我编辑正确了@罗伯特