How can you get System.OutOfMemoryException while the application is not using that much memory

I am getting this error and cannot figure out why this is happening.

I am using Windows 8.1 64-bit with 32GB of RAM

The app is 32 bit and only uses about 400MB in the task manager and even less when checked with GC.GetTotalMemory(false)

How can I debug this error?

C # 4.5 application

Here's the largest compressed string data in the database (322KB):

Here's an uncompressed line from that biggest data (4837 KB):

Here unpack the line function

private static string Un_GZip_String(string compressedText)
        using (var memoryStream = new MemoryStream())
            byte[] gZipBuffer = Convert.FromBase64String(compressedText);
            int dataLength = BitConverter.ToInt32(gZipBuffer, 0);
            memoryStream.Write(gZipBuffer, 4, gZipBuffer.Length - 4);

            var buffer = new byte[dataLength];

            memoryStream.Position = 0;
            using (var gZipStream = new GZipStream(memoryStream, System.IO.Compression.CompressionMode.Decompress))
                gZipStream.Read(buffer, 0, buffer.Length);

            return Encoding.UTF8.GetString(buffer);

enter image description here


source to share

1 answer

I would recommend downloading the ANTI Performance Profiler:

It will set exactly why you are getting the out of memory exception and has a 30 day free trial - you should have enough time for that.

As someone said in the comments, it can be a bunch of large objects as it can get out of hand pretty quickly. The performance profiler will quickly tell you what the problem is.



All Articles