Importance of Debug and Release in .Net

Introduction

 
In this blog, we are discussing the importance of debugging and release. Debug and release are build modes.
 
Let's discuss the differences in Debug and Release.
 
1). Priority of the build mode.
 
Debug Mode: When we are developing the application.
Release Mode: When we are going to production mode or deploying the application to the server.
 
2). Code optimization 
 
Debug Mode: The debug mode code is not optimized.
Release Mode: The release mode code is optimized.
 
Let's demonstrate the code optimization through a simple program.
  1. class program   
  2. {  
  3.    
  4. static void main (string[] args)  
  5. {  
  6.    M1();  
  7. }  
  8.    
  9. static void M1()  
  10. {  
  11.    M2();  
  12. }  
  13.   
  14. static void M2();  
  15. {  
  16.    M3();  
  17.   
  18. }  
  19.   
  20. static void M3()  
  21. {  
  22.    throw new Exception("some error");  
  23. }  
  24. }  
The execution of the program will be like this. The first main method will execute later, M1, M2, and M3. In the M3 method, we are throwing an exception. 
 
Run this program in debug mode and see your output window. Please check the below snapshot.
 
 
 
See in debug mode we can see the complete stack trace of the program execution.
 
Run this program in release mode and see your output window. Please check the bellow snapshot.
 
 
 
In release mode, we cannot see the complete stack trace
 
Performance
 
Debug Mode: In debug mode the application will be slow.
Release Mode: In release mode the application will be faster.
 
Debug Symbols
 
Debug Mode: In the debug mode code, which is under the debug, symbols will be executed. 
Release Mode: In release mode code, which is under the debug, symbols will not be executed.
 
Please check the below code snippet:
  1. class program  
  2. {  
  3. static void main(string[] args)  
  4. {  
  5. #if DEBUG  
  6. console.writeLine("this line will be executed in debug mode only");  
  7. #endif  
  8. }  
  9. }  
 

Summary

 
In this blog, we discussed the debug and release mode differences.