Thursday, 5 September 2013

Static list and Garbage collector?

Static list and Garbage collector?

I've an application which may use a lot of data in each calculus.
I have a "class A" which contains a lot of attributes. I've around 10k
objects of this class.
So my idea was to load them only one time from the database and use them
to search for example.
So I created a List :
public static List<ClassA>
in my application.
After some tests it's really faster than loading everytime my data from
the database.
But I don't think this is a good way to do it ? What about the garbage
collector ? Can it becomes perturbed by this huge List of Data ?
My second idea was to split my Class1 into different classes to have
smaller requests from the DB. My code is more clean for sure. But really
slow now.
The only big issue I see in the List method is the persistence of my Data
: I have to modify the elements from my List (so search them in the list)
and also persist them through EntityFramework instead of getting them from
EF, modifying them then persisting them through EF.
For sure it seems to be "better" to avoid the list, but the performances
are so bad if I don't use it.
I used the profiler with the List, and it took a lot of time into the
creation of the lists (each time I search something it returns a smaller
list : for example take all objects where the attribute "Name" equals
"blabla")
Can you help me in my reflexion ?
Thank you

No comments:

Post a Comment