Replies: 2 comments 3 replies
-
I cannot reproduce this behavior based on your minimal description. I can't guess what's going on without seeing some code. |
Beta Was this translation helpful? Give feedback.
-
Thanks for responding so quickly. So I am creating a new model when reading the csv file with many columns (50 plus) with many rows of data (about 7,000) all is good except the memory usage particularly with csv.GetString() or other types. I am just setting this up in a blazor project with latest .net etc.. I have this set up to call these Get methods upon OnInitialize (page load). When I refresh, the memory continues to stack ( about 230 mb) each time. I was able to get a work around with garbage collector and I can dump those objects immediately after. I also tried the old way of using statement. Just noticed that maybe we have to handle memory usage ourselves. I have used excel interop and realized you have to run garbage collector as well after opening a workbook and closing it. BTW what is the main use of Original way - following examples. // inside method
using var csv = CsvDataReader.Create(FilePath); // Getting a csv from file path here
while(await csv.ReadAsync())
{
someModel.Add( new someModel()
{
id = csv.GetInt32(0);
name = csv.GetString(1);
date = csv.GetDateTime(2);
///50 more columns
}
csv.Close();
} What I did to alleviate memory issue with GC. Can be in main OnInitialized method instead. // inside method
using (CsvDataReader csv = CsvDataReader.Create(FilePath))
{
while (await csv.ReadAsync())
{
someModel.Add(new someModel()
{
id = csv.GetInt32(0);
name = csv.GetString(1);
date = csv.GetDateTime(2);
///50 more columns
});
}
csv.Close();
}
GC.Collect();
GC.WaitForPendingFinalizers();
return someModel; |
Beta Was this translation helpful? Give feedback.
-
I noticed that when you run a method over again when using
CsvDataReader
the Process memory dramatically increases. Am I missing something here? I calledcsv.Close()
after theReadAsync()
operation but nothing happens.Beta Was this translation helpful? Give feedback.
All reactions