简体   繁体   中英

Memory usage is not released in IIS express

I am trying to unzip a file using below code.

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();
     }
}

My Issue :

I have published my web project and hosted in IIS Express-8. While calling this UnZip method Memory usage reaches more than 600MB and it never dropdown after come out from the method more than one hour. so if i again call the same method i am getting MemoryOutOfException error because by default iis express have 800MB so i am getting the error.

I don't want to increase the memory size of the IIS Express . May be I have did some mistake in my code but i can't find a issue.

Help me to find a issue and solve my problem.

I would put "zip.Close();" inside using block

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM