代码如下:
/// <summary> /// ZIP解压 /// </summary> /// <param name="fileName">fileName</param> /// <returns>Decompress</returns> public static string Decompress(string fileName) { byte[] file = null; using (MemoryStream outBuffer = new MemoryStream()) { using (FileStream stream = new FileStream(fileName, System.IO.FileMode.Open, System.IO.FileAccess.Read)) { using (ZipInputStream compressedzipStream = new ZipInputStream(stream)) { byte[] block = new byte[10240]; ZipEntry entry = null; while ((entry = compressedzipStream.GetNextEntry()) != null) { while (true) { int bytesRead = compressedzipStream.Read(block, 0, block.Length); if (bytesRead <= 0) { break; } else { outBuffer.Write(block, 0, bytesRead); } } } compressedzipStream.Dispose(); compressedzipStream.Close(); } stream.Dispose(); stream.Close(); } file = outBuffer.ToArray(); outBuffer.Dispose(); outBuffer.Close(); } return Encoding.UTF8.GetString(file); }
这段代码跑一次,内存就长一倍,改释放的资源都释放了呀??