Differences between debug and release in Visual Studio

Source: Internet
Author: User

In Visual Studio, there are two modes for generating an application: Debug and release. How can we choose between them?


Assume that there is such a simple piece of code that calls Methods M1 and M1 in the main program to call the M2 method, m2 to call the M3 method, and M3 to throw an exception.

    class Program
    {
        static void Main(string[] args)
        {
            M1();
            Console.ReadKey();
        }
        static void M1()
        {
            M2();
        }
        static void M2()
        {
            M3();
        }
        static void M3()
        {
            throw new Exception("error");
        }
    }

Select the "debug" mode and place the breakpoint on the console. readkey (); line of code. Click "Debug> WINDOW> call stack" to display the "call stack" window information, as shown below:

 

Select the "release" mode and debug it again. The display is as follows:

 

From the stack information, we can see that debugging in debug and release modes consumes more memory, so it runs slowly. The release mode is optimized, it consumes less memory, so it runs faster.

 

In actual situations, you should deploy the applications generated in the release mode to the server, because the applications generated in the remease are optimized and compared to the applications generated in the debug mode, it runs faster.

 

In addition, if you want to run a piece of code only in debug mode, you can use the debug flag to write it as follows:

#if DEBUG
 Console.WriteLine(DateTime.Now);
#endif

 

In general:
1. Compared with the debug mode, the release mode is more optimized and suitable for deployment to the server after the project is completed. The debug mode is more suitable for debugging.
2. The Code marked with debug is automatically deleted in release mode.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.