Skip to content
This repository has been archived by the owner on Nov 24, 2020. It is now read-only.

Memory leak issue #166

Open
limengning opened this issue Mar 10, 2020 · 2 comments
Open

Memory leak issue #166

limengning opened this issue Mar 10, 2020 · 2 comments

Comments

@limengning
Copy link

Use NPOI in dotnet core web api to create excel file.
The memory usage of the website is always rising.

@phucnh1993
Copy link

image
I run on K8S and use NPOI read file Excel from a Stream

My Code:
var checkFile = true;
ISheet sheet;
IFont font;
using (MemoryStream ms = new MemoryStream())
{
var data = Convert.FromBase64String(file.FileBase);
await ms.WriteAsync(data, 0, data.Length);
ms.Position = 0;
var temp = Path.GetExtension(file.FileName);
if (Path.GetExtension(file.FileName).Equals(".xls"))
{
var book = new HSSFWorkbook(ms);
font = book.CreateFont();
sheet = book.GetSheet("Sheet1");
}
else
{
var book = new XSSFWorkbook(ms);
font = book.CreateFont();
sheet = book.GetSheet("Sheet1");
}
int rowIndex = 1;
IRow rowData;
font.Color = HSSFColor.Red.Index;
var listThread = new List();
List hashCodes = new List();
MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
while ((rowData = sheet.GetRow(rowIndex)) != null)
{
rowIndex++;
string dataDup = string.Format("{0}{1}{2}{3}", rowData.GetCell(numberCell).ToString(), rowData.GetCell(numberCell).ToString(), rowData.GetCell(numberCell).ToString(), rowData.GetCell(numberCell).ToString());
colNum = null;
colStr = null;
colLen = null;
rowData = null;
}
ms.Flush();
ms.Close();
}

@phucnh1993
Copy link

hình ảnh
Tôi chạy trên K8S và sử dụng NPOI đọc tệp Excel từ Luồng

Mã của tôi:
var checkFile = true;
Bảng ISheet;
Phông chữ IFont;
bằng cách sử dụng (MemoryStream ms = new MemoryStream ())
{
var data = Convert.FromBase64String (file.FileBase);
đang chờ ms.WriteAsync (dữ liệu, 0, dữ liệu. Độ dài);
ms.P Vị trí = 0;
var temp = Path.GetExtension (file.FileName);
if (Path.GetExtension (file.FileName) .Equals (". xls"))
{
var book = new HSSFWorkbook (ms);
font = book.CreateFont ();
sheet = book.GetSheet ("Sheet1");
}
khác
{
var book = new XSSFWorkbook (ms);
font = book.CreateFont ();
sheet = book.GetSheet ("Sheet1");
}
int row Index = 1;
IRow hàngData;
font.Color = HSSFColor.Red. Index;
var listThread = Danh sách mới ();
Danh sách hashCodes = Danh sách mới ();
MD5CryptoServiceProvider md5 = MD5CryptoServiceProvider ();
while (rowData = sheet.GetRow (row Index))! = null)
{
rowIndex ++;
chuỗi dataDup = string.Format ("{0} {1} {2} {3}", rowData.GetCell (numberCell) .ToString (), rowData.GetCell (numberCell) .ToString (), rowData.GetCell (numberCell) .ToString (), rowData.GetCell (numberCell) .ToString ());
colNum = null;
colStr = null;
colLen = null;
hàngData = null;
}
ms.Flush ();
ms. Đóng ();
}

I user DotNetCore 3.1

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants