0

Just for curiosity, I made a small console application as the following code :

class Program
    {
        static void Main(string[] args)
        {
            byte[] b = new byte[Int32.MaxValue / 4]; // about 536870911
            Console.ReadLine();
        }
    }

When I run it and it goes to Console.ReadLine() I check the task manager. It shows me that my application is only using 2508KB of memory. How could it be ?

2
  • Try writing ones to the entire entire array. I suspect it's the same lazy allocation thing that affects native programs. Commented Jul 10, 2014 at 18:09
  • 3
    The variable is never used. The compiler is entirely within it's rights to remove all of the code for that allocation entirely. Commented Jul 10, 2014 at 18:15

1 Answer 1

2

Here are my results:

In debug mode:

enter image description here

In release mode:

enter image description here

Yellow is private bytes, red is working set. In release mode, since nothing uses your variable, it gets optimized away by the compiler.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.