Click here to Skip to main content
14,302,627 members
   

C#

 
QuestionOutOfMemoryException help please Pin
DTGeek17-Jul-19 5:07
memberDTGeek17-Jul-19 5:07 
AnswerRe: OutOfMemoryException help please Pin
OriginalGriff17-Jul-19 5:21
protectorOriginalGriff17-Jul-19 5:21 
AnswerRe: OutOfMemoryException help please Pin
Gerry Schmitz17-Jul-19 6:07
mveGerry Schmitz17-Jul-19 6:07 
GeneralRe: OutOfMemoryException help please Pin
DTGeek17-Jul-19 6:11
memberDTGeek17-Jul-19 6:11 
AnswerRe: OutOfMemoryException help please Pin
Luc Pattyn17-Jul-19 7:42
professionalLuc Pattyn17-Jul-19 7:42 
GeneralRe: OutOfMemoryException help please Pin
DTGeek17-Jul-19 8:17
memberDTGeek17-Jul-19 8:17 
GeneralRe: OutOfMemoryException help please Pin
Luc Pattyn17-Jul-19 8:20
professionalLuc Pattyn17-Jul-19 8:20 
GeneralRe: OutOfMemoryException help please Pin
Luc Pattyn17-Jul-19 12:53
professionalLuc Pattyn17-Jul-19 12:53 
Some additional thoughts.

What I previously explained about possible causes for OutOfMemoryException are actually possible causes for StackOverflowException. In order to get OutOfMemory (and not StackOverflow), one needs to allocate lots of objects on the heap (not the stack).


There basically are two scenario's possible for OutOfMemory:

[1]. code is recursing abnormally (so it should result in a StackOverflow) but the heap gets exhausted before the stack is exhausted.

If we assume a workspace of 2GB and a stack size of 1MB and a stack frame of say 1KB (mainly used for local variables of the recursing method), one could recurse 1000 times before getting a stack overflow. To exhaust 2GB in less than 1000 recursions, each recursion needs to consume 2MB which is not at all impossible. If you have objects of such size, look for unlimited recursion (property recursion, function recursion, event avalanche, ...).

[2]. Even when code is running normally (I mean without abnormal recursion), too many and/or too large objects might get allocated (or remain allocated). That depends on the size of the problems your program is dealing with, and the efficiency and correctness of your code.



Things to look for are:
- object references might get stored in static lists, keeping the objects alive forever, even when they aren't really needed any more by the program;
- objetcs with a Dispose() method that aren't disposed of keep hold of their unmanaged memory; this applies to almost all GUI objects.

I stand by my suggestion to use logging. You could even log memory usage statistics periodically and/or when creating large objects.

Things that may point you in the right direction:
- does your app remain responsive (i.e. reacting to user interaction) up to the OutOfMemory exception?
- does your app do everything it should do, and only throws OutOfMemory after some time?
- how long does it take your app from seeming dead to actually throw OutOfMemory?


One wild guess: some operations throw an exception of unexpected type; example: Image.FromFile sometimes throws OutOfMemory when it does not understand the file format (ref[^]). So a single bad data file could be the cause of all this trouble... This is a sufficient reason to always properly display or log all Exception information (message AND stack trace) and never swallow an exception.

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

AnswerRe: OutOfMemoryException help please Pin
Eddy Vluggen17-Jul-19 13:50
mveEddy Vluggen17-Jul-19 13:50 
QuestionQuick Question - Data Validation Range with DateTime Pin
Kevin Marois16-Jul-19 7:05
professionalKevin Marois16-Jul-19 7:05 
AnswerRe: Quick Question - Data Validation Range with DateTime Pin
OriginalGriff16-Jul-19 8:16
protectorOriginalGriff16-Jul-19 8:16 
AnswerRe: Quick Question - Data Validation Range with DateTime Pin
Richard Deeming16-Jul-19 9:15
mveRichard Deeming16-Jul-19 9:15 
AnswerRe: Quick Question - Data Validation Range with DateTime Pin
BillWoodruff16-Jul-19 20:34
mveBillWoodruff16-Jul-19 20:34 
AnswerRe: Quick Question - Data Validation Range with DateTime Pin
Eddy Vluggen16-Jul-19 23:22
mveEddy Vluggen16-Jul-19 23:22 
GeneralRe: Quick Question - Data Validation Range with DateTime Pin
BillWoodruff17-Jul-19 0:43
mveBillWoodruff17-Jul-19 0:43 
GeneralRe: Quick Question - Data Validation Range with DateTime Pin
Eddy Vluggen17-Jul-19 1:09
mveEddy Vluggen17-Jul-19 1:09 
GeneralRe: Quick Question - Data Validation Range with DateTime Pin
OriginalGriff17-Jul-19 2:49
protectorOriginalGriff17-Jul-19 2:49 
GeneralRe: Quick Question - Data Validation Range with DateTime Pin
Eddy Vluggen17-Jul-19 13:53
mveEddy Vluggen17-Jul-19 13:53 
AnswerRe: Quick Question - Data Validation Range with DateTime Pin
Gerry Schmitz17-Jul-19 6:15
mveGerry Schmitz17-Jul-19 6:15 
Questionhow I input Hebrew from winForm to mySql Pin
Member 1387299916-Jul-19 0:17
memberMember 1387299916-Jul-19 0:17 
AnswerRe: how I input Hebrew from winForm to mySql Pin
OriginalGriff16-Jul-19 0:36
protectorOriginalGriff16-Jul-19 0:36 
GeneralRe: how I input Hebrew from winForm to mySql Pin
Member 1387299916-Jul-19 0:54
memberMember 1387299916-Jul-19 0:54 
GeneralRe: how I input Hebrew from winForm to mySql Pin
Luc Pattyn16-Jul-19 3:31
professionalLuc Pattyn16-Jul-19 3:31 
GeneralRe: how I input Hebrew from winForm to mySql Pin
Member 1387299916-Jul-19 7:08
memberMember 1387299916-Jul-19 7:08 
Questionregular expression to extract data from a html table with TD marked with id using C# Pin
Indexon India15-Jul-19 6:06
memberIndexon India15-Jul-19 6:06 

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.