0

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>?

enter image description here

Thomas Weller
  • 55,411
  • 20
  • 125
  • 222
Reza Akraminejad
  • 1,412
  • 3
  • 24
  • 38
  • *2mg file* loading? Umm that's doesn't sound efficient. Instead read line by line and do processing. – Rahul Sep 06 '15 at 10:41
  • No. that's not the solution and won't solve the problem – Reza Akraminejad Sep 06 '15 at 11:06
  • How many lines are you iterating over? Seems like you're potentially generating alot of strings. – Yuval Itzchakov Sep 06 '15 at 11:43
  • It's almost impossible to diagnose your issue with a single line of code, and not much information. You also just tell us you have a 'memory problem', but not any more details further than that. – Rob Sep 06 '15 at 12:29
  • @Rob I added a picture of memory dump analyze. hope it will help – Reza Akraminejad Sep 07 '15 at 05:16
  • What memory problem do you have? Post some relevant code. Provide better context of the issue you are facing. What have you tried to solve the issue? – Code.me Sep 07 '15 at 05:23
  • the main exe of program gets more memory, about 300 mg after working long time. I think garbage collector cant collect it, cause of many requests and interaction with program. – Reza Akraminejad Sep 07 '15 at 05:36

1 Answers1

0

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.

Thomas Weller
  • 55,411
  • 20
  • 125
  • 222
  • All items Are needed in from start to end of program. I use them for checking some values. and items won't increase or decrease until end. I think problem is architecture using this access method. maybe something better than tuple or static is not used correctly in this place – Reza Akraminejad Sep 08 '15 at 05:09
  • If the items are used from the beginning to the end, it doesn't matter whether they are static or not from memory point of view. The objects will always be *rooted*. However, from a design or architectural point of view, there may be better solutions. – Thomas Weller Sep 08 '15 at 17:10
  • so will you offer better architecture designs for more reading and getting new ideas from that – Reza Akraminejad Sep 09 '15 at 06:43
  • @Hamed_gibago: no. That's something for [programmers](http://programmers.stackexchange.com/tour) – Thomas Weller Sep 09 '15 at 19:27