What are the possible reasons of OutofMemory
exception.
Memory allocations should be handled by GC.
How much memory is allocated/Available to normal .NET/C# application
In our application it comes at different places like Stream.ReadToEnd()
and DataTable.WriteXml(Memory stream)
function.
Environment is .Net C#
1) An easy way to solve OutOfMemoryError in java is to increase the maximum heap size by using JVM options "-Xmx512M", this will immediately solve your OutOfMemoryError.
An OutOfMemoryException exception has two major causes: You are attempting to expand a StringBuilder object beyond the length defined by its StringBuilder. MaxCapacity property. The common language runtime cannot allocate enough contiguous memory to successfully perform an operation.
OutOfMemoryError exception. Usually, this error is thrown when there is insufficient space to allocate an object in the Java heap. In this case, The garbage collector cannot make space available to accommodate a new object, and the heap cannot be expanded further.
The OutOfMemory exception happens whenever a call to any of the following MSIL instructions fails
Which basically the operations that allocate new memory in the heap, in your case the Stream.ReadToEnd apparently allocates array of bytes internally to load the stream in memory, so if the file in big enough to break the process it will throw this exception.
Either you are using more memory than the app has available to it. In this case you will need to work out how to make your memory usage more efficient. Using Files / Database to store data you arent immediately using may be necessary..
Or, you have a memory leak. In which case you need to look at removing references to memory when you are no longer using them so the GC can free up the memory.
If you are using C# or .Net you can use the CLR Profiler to analyse your memory to see how it is being used. CLR Profiler
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With