This is a very strange problem here:
I have a solution that consists of two projects, one is C# and the other is a C++/CLR.
C++/CLR project loads a DLL and exposes its functionality as a managed DLL to be used by C#.
When the application finishes, the DLL should be deleted. I have a suitable code in my code to free the library.
The last part of this process is to actually free the library and I have this code (This is C++ code)
As you can see there is a breakpoint and also an std::cout line.
If I comment out the std::cout line, then the breakpoint is not called.
If I let the std::cout active in the code, the breakpoint hits and it prints out.
I am building in Debug mode so I don't believe the code removed as part of optimization. I cleaned the project and have the same issue. I rebuild the project and have the same issue.
I am wondering why this is happening and can I be sure that the library is freed in this case?
Edit 1
I think there is no code optimization (I am using MSVC 2019):