Click here to Skip to main content
15,887,350 members
Home / Discussions / C#
   

C#

 
GeneralRe: Memory leak trouble with Linq to Sql and multiple threads Pin
JD8614-Jan-16 4:07
JD8614-Jan-16 4:07 
GeneralRe: Memory leak trouble with Linq to Sql and multiple threads Pin
JD8614-Jan-16 4:26
JD8614-Jan-16 4:26 
GeneralRe: Memory leak trouble with Linq to Sql and multiple threads Pin
JD8614-Jan-16 14:05
JD8614-Jan-16 14:05 
GeneralRe: Memory leak trouble with Linq to Sql and multiple threads Pin
Luc Pattyn14-Jan-16 18:26
sitebuilderLuc Pattyn14-Jan-16 18:26 
GeneralRe: Memory leak trouble with Linq to Sql and multiple threads Pin
JD8617-Jan-16 16:09
JD8617-Jan-16 16:09 
GeneralRe: Memory leak trouble with Linq to Sql and multiple threads Pin
Luc Pattyn17-Jan-16 17:10
sitebuilderLuc Pattyn17-Jan-16 17:10 
GeneralRe: Memory leak trouble with Linq to Sql and multiple threads Pin
JD8617-Jan-16 17:21
JD8617-Jan-16 17:21 
GeneralRe: Memory leak trouble with Linq to Sql and multiple threads Pin
Luc Pattyn17-Jan-16 18:32
sitebuilderLuc Pattyn17-Jan-16 18:32 
1. The C# code remains the same; after JIT compilation, your code is somewhat larger, this won't be relevant.
IIRC the smallest object grows from 32 to 48B when switching to x64.
And obviously every reference grows from 4 to 8B.
So memory usage is bound to be less than twice the original, and typically much less than that, as value types, texts, etc. don't grow at all.

2.
A piece of code that returns a collection and doesn't care about fragmentation issues probably is based on an array; so is the ToList() you're using in LINQ. An array (or an array-based class) is just the easiest to produce and consume.

There are alternatives, such as streaming (produce while consuming, never have it all in memory; that still is likely to contain an array internally, a smaller one). Or just asking for less data at once (you could keep start and end datetimes closer to each other, possibly in a loop, inside ExchActions.Get_TotalSentMessages().

BTW: My ListOfLists class is an IEnumerable, i.e. to the consumer it only shows one element at a time. That is extreme streaming! Fortunately the compiler converts "yield return" statements in all the code required to keep track of where the consumer is currently fetching the data.

3.
What the powershell interface gives you is an ICollection, which is slightly more than an IEnumerable (e.g. it has a Count property, and an Add method). From this one can only gamble how it is implemented. Or look at it using Reflector or some other tool.

4.
I'm not sure you need ToList() in your LINQ statements. Dit you try without?
Select() returns an IEnumerable, and I expect that is all you are needing. I don't know how Select is implemented, I would hope it works in some kind of streaming mode (IEnumerable in, IEnumerable out, and produce while being consumed).
If this holds true, that is a number of potentially big objects you no longer need.
You would have to declare differently, and count yourself (while at it, I also summed the
bytes!):
IEnumerable<MessageTrackingLog> totalSentLogs=LINQ statement without .ToList();
int sentCount=0;
int sentBytes=0;
foreach(MessageTrackingLog item in totalSentLogs) {
    sentCount++;
    sentBytes+=item.TotalBytes;
}

which is much cheaper than having the CLR hand you a List first, and then use LINQ to process it.


Smile | :)
Luc Pattyn [My Articles] Nil Volentibus Arduum

GeneralRe: Memory leak trouble with Linq to Sql and multiple threads Pin
JD8619-Jan-16 3:26
JD8619-Jan-16 3:26 
GeneralRe: Memory leak trouble with Linq to Sql and multiple threads Pin
JD8621-Jan-16 4:04
JD8621-Jan-16 4:04 
GeneralRe: Memory leak trouble with Linq to Sql and multiple threads Pin
Luc Pattyn21-Jan-16 15:06
sitebuilderLuc Pattyn21-Jan-16 15:06 
Questionbetter way to Linqify this ? Pin
BillWoodruff9-Jan-16 2:01
professionalBillWoodruff9-Jan-16 2:01 
AnswerRe: better way to Linqify this ? Pin
Sascha Lefèvre9-Jan-16 2:25
professionalSascha Lefèvre9-Jan-16 2:25 
GeneralRe: better way to Linqify this ? Pin
BillWoodruff11-Jan-16 8:06
professionalBillWoodruff11-Jan-16 8:06 
GeneralRe: better way to Linqify this ? Pin
Sascha Lefèvre11-Jan-16 8:37
professionalSascha Lefèvre11-Jan-16 8:37 
GeneralRe: better way to Linqify this ? Pin
Richard Deeming11-Jan-16 11:00
mveRichard Deeming11-Jan-16 11:00 
GeneralRe: better way to Linqify this ? Pin
Sascha Lefèvre11-Jan-16 23:00
professionalSascha Lefèvre11-Jan-16 23:00 
GeneralRe: better way to Linqify this ? Pin
BillWoodruff12-Jan-16 0:19
professionalBillWoodruff12-Jan-16 0:19 
AnswerRe: better way to Linqify this ? Pin
PIEBALDconsult9-Jan-16 6:09
mvePIEBALDconsult9-Jan-16 6:09 
GeneralRe: better way to Linqify this ? Pin
OriginalGriff9-Jan-16 6:17
mveOriginalGriff9-Jan-16 6:17 
GeneralRe: better way to Linqify this ? Pin
Jörgen Andersson9-Jan-16 12:53
professionalJörgen Andersson9-Jan-16 12:53 
GeneralRe: better way to Linqify this ? Pin
BillWoodruff9-Jan-16 13:52
professionalBillWoodruff9-Jan-16 13:52 
GeneralRe: better way to Linqify this ? Pin
PIEBALDconsult9-Jan-16 16:05
mvePIEBALDconsult9-Jan-16 16:05 
GeneralRe: better way to Linqify this ? Pin
BillWoodruff11-Jan-16 8:10
professionalBillWoodruff11-Jan-16 8:10 
GeneralRe: better way to Linqify this ? Pin
PIEBALDconsult11-Jan-16 14:33
mvePIEBALDconsult11-Jan-16 14:33 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.