简体   繁体   中英

huge memory usage in static class

I have a static list

List<Tuple<string, string>> binariesList = new List<Tuple<string, string>>()

in an static class called Class1 .

The non-static class Class2 use Class1 a lot of times. Instances of Class2 are constructed often, I think there is no problem with that (Garbage Collcetor collects it).

But just at start of program, Class1 loads a file of about 2 MB into binariesList .

In the static load() method I use this for loading for each element:

dic.Add(new Tuple<string,string>(temp[i].Split(',')[1].Trim(), temp[i].Split(',')[0].Trim()));

I have a memory problem and saw there is a high reference count and size(bytes) columns, in the memory dump I analyze for that Tuple<string,string> .

Is there a problem with that Tuple<string,string> ?

在此处输入图片说明

That's not a memory leak I'd say. It's the intended behavior of your program as far as I can tell from your question.

The problem is neither with the Tuple nor with the List - it's the way you use the list to add items to it.

To avoid crashing due to an OutOfMemoryException , simply remove items from the list that are not needed any more.

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