Click here to Skip to main content
15,905,028 members
Home / Discussions / C#
   

C#

 
GeneralRe: Memory leak trouble with Linq to Sql and multiple threads Pin
Luc Pattyn10-Jan-16 17:00
sitebuilderLuc Pattyn10-Jan-16 17:00 
GeneralRe: Memory leak trouble with Linq to Sql and multiple threads Pin
JD8610-Jan-16 17:06
JD8610-Jan-16 17:06 
GeneralRe: Memory leak trouble with Linq to Sql and multiple threads Pin
Luc Pattyn11-Jan-16 2:31
sitebuilderLuc Pattyn11-Jan-16 2:31 
GeneralRe: Memory leak trouble with Linq to Sql and multiple threads Pin
Richard MacCutchan10-Jan-16 20:58
mveRichard MacCutchan10-Jan-16 20:58 
GeneralRe: Memory leak trouble with Linq to Sql and multiple threads Pin
Luc Pattyn11-Jan-16 2:21
sitebuilderLuc Pattyn11-Jan-16 2:21 
AnswerRe: Memory leak trouble with Linq to Sql and multiple threads Pin
Gerry Schmitz10-Jan-16 7:42
mveGerry Schmitz10-Jan-16 7:42 
GeneralRe: Memory leak trouble with Linq to Sql and multiple threads Pin
Dave Kreskowiak10-Jan-16 8:29
mveDave Kreskowiak10-Jan-16 8:29 
GeneralRe: Memory leak trouble with Linq to Sql and multiple threads Pin
Gerry Schmitz10-Jan-16 9:04
mveGerry Schmitz10-Jan-16 9:04 
GeneralRe: Memory leak trouble with Linq to Sql and multiple threads Pin
JD8610-Jan-16 16:33
JD8610-Jan-16 16:33 
GeneralRe: Memory leak trouble with Linq to Sql and multiple threads Pin
Gerry Schmitz10-Jan-16 17:40
mveGerry Schmitz10-Jan-16 17:40 
GeneralRe: Memory leak trouble with Linq to Sql and multiple threads Pin
JD8611-Jan-16 5:01
JD8611-Jan-16 5:01 
GeneralRe: Memory leak trouble with Linq to Sql and multiple threads Pin
JD8612-Jan-16 6:24
JD8612-Jan-16 6:24 
GeneralRe: Memory leak trouble with Linq to Sql and multiple threads Pin
Luc Pattyn12-Jan-16 15:50
sitebuilderLuc Pattyn12-Jan-16 15:50 
GeneralRe: Memory leak trouble with Linq to Sql and multiple threads Pin
JD8612-Jan-16 16:29
JD8612-Jan-16 16:29 
GeneralRe: Memory leak trouble with Linq to Sql and multiple threads Pin
Luc Pattyn12-Jan-16 17:16
sitebuilderLuc Pattyn12-Jan-16 17:16 
GeneralRe: Memory leak trouble with Linq to Sql and multiple threads Pin
JD8612-Jan-16 17:30
JD8612-Jan-16 17:30 
GeneralRe: Memory leak trouble with Linq to Sql and multiple threads Pin
Luc Pattyn12-Jan-16 17:46
sitebuilderLuc Pattyn12-Jan-16 17:46 
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 
1. Yes, your first paragraph is correct.

2.
I have almost zero experience with the improved LOH GC in .NET 4.5/4.5.1/4.5.2/4.6 (yes it came incrementally!), I've read it all and I'm working on some experiments, however I do not fully trust it for the potential side effects. I'd rather avoid the fragmentation if there happens to be a reasonable way to do so. Keep in mind an LOH compaction is a potentially huge operation that is rumored to maybe take ten seconds or so, in which time your app probably doesn't respond to anything.

3.
Once you got an OOMExc, you're stuck, unless you put try-catch AND retry logic everywhere! As an OOMExc could occur in many places, you would have to:
(a) either include a lot of GCSettings.LargeObjectHeapCompactionMode=...Once statements,
(b) or trust that by setting it once at the start of some/all intervals would suffice.
But that assumption might be hard to proof correct.

Anyway I'd be more interested in the newer forms of GC.Collect, see here[^] but that requires 4.6

You could also set LargeObjectHeapCompactionMode to once AND call GC.Collect(2) to force a LOH collect right away. That should work on 4.5.1

BTW: I've seen an article suggesting a timer that periodically causes an LOH compaction, but that sounds horrible, it would not synchronize to your app at all.

4.
I'm inclined to recommend you eventually switch to a 64-bit app if that is at all possible. Yes pointers become twice as large (so lists become LOH candidates sooner), but the usable virtual address space theoretically grows from 2 GB (maybe 3 or 4) up to 8 TB (other limits may apply, the Windows memory system is pretty complex!).

A 64-bit app needs a CPU that supports x64 and a Windows OS version that does the same (check under MyComputer/Properties, not sure how virtual machines handle it), and a .NET app that is built for "Any CPU", an option in Build/ConfigurationManager (no problem, unless you are referencing libraries/DLLs that are built explicitly for 32-bit).

5.
Warning: every little step you take to solve a problem like this may make it less probable, so it becomes harder to detect if anything more needs to be done. It is essential you find and use a way to "stress test" your code, maybe by shortening intervals, entering duplicates of actual list elements, etc.

6.
Finally, depending on how your program is going to be used, maybe an automatic periodic restart is quite acceptable. Application.Restart()[^] works really well!

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

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 

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.