GC Question

Quick question, I know Debug.Print commands are (at least in full .NET) stripped when compiled in release mode…does this affect Debug.GC(true)?

I think it affects ALL debug outputs.

using Reflector:

public static class Debug
{
    // Methods
    [Conditional("DEBUG")]
    public static void Assert(bool condition);
    [Conditional("DEBUG")]
    public static void Assert(bool condition, string message);
    [Conditional("DEBUG")]
    public static void Assert(bool condition, string message, string detailedMessage);
    [MethodImpl(MethodImplOptions.InternalCall)]
    public static extern void EnableGCMessages(bool enable);
    [MethodImpl(MethodImplOptions.InternalCall)]
    public static extern uint GC(bool force);
    [MethodImpl(MethodImplOptions.InternalCall)]
    public static extern void Print(string text);
}

Print() and GC() don’t have the Conditional(“DEBUG”) attribute. So they work in release mode !
Print() is easy to test :slight_smile:

Another thing to remember is [Conditional(“DEBUG”)] methods are not removed from IL or pe file that is sent to device. They are removed by the JIT in big .Net only. MF has no JIT, so they are called when debugger is attached, even in Release build. If the debugger is not attached, not sure how MF handles skipping them. To really remove them, you would need #if directive blocks like:

[Conditional("DEBUG")]
public void MyDebugMethod()
{
    #if DEBUG // Code inside #if block is removed by c# compiler if not Debug build.
    Debug.Print("hello");
    // other code.
    #endif
}

The MyDebugMethod will remain in release code, but will be empty.

Thanks guys! There are obviously a few points in my project I wanted to make sure GarbageCollection was forced to call; like after quitting an application.