title: Executing c++ object file in command line gives different output than VScode debugger
body: <p>I was following a youtube tutorial that made a simple memory allocation tracker by overriding the <code>new</code> and <code>delete</code> operators. It uses an object to keep track of the stats. Its pretty simple, here is the code</p>
  <pre><code>#include &lt;iostream&gt;
  
  struct AllocationMetics
  {
      uint32_t TotalAllocated = 0;
      uint32_t TotalFreed = 0;
      uint32_t TotalUsage() { return TotalAllocated - TotalFreed; }
  };
  
  static AllocationMetics s_AllocationMetrics;
  
  void* operator new(size_t size)
  {
      s_AllocationMetrics.TotalAllocated += size;
      return malloc(size);
  }
  
  void operator delete(void* memory, size_t size) noexcept
  {
      s_AllocationMetrics.TotalFreed += size;
      std::cout &lt;&lt; size &lt;&lt; &quot; added to total freed \n&quot;;
      free(memory);
  }
  
  void LogMemStat()
  {
      std::cout &lt;&lt; &quot;Total memory allocated: &quot; &lt;&lt; s_AllocationMetrics.TotalAllocated &lt;&lt; std::endl
          &lt;&lt; &quot;Total memory freed: &quot; &lt;&lt; s_AllocationMetrics.TotalFreed &lt;&lt; std::endl
          &lt;&lt; &quot;Total memory usage: &quot; &lt;&lt; s_AllocationMetrics.TotalUsage() &lt;&lt; std::endl &lt;&lt; std::endl;
  }
  
  struct Object
  {
      int x;
  };
  
  int main()
  {
      LogMemStat();
  
      Object* obj = new Object;
      LogMemStat();
  
      delete obj;
      LogMemStat();
  
      return 0;
  }
  </code></pre>
  <p>when I compile with g++20 on my Mac (running on M1, Monterey 12.2.1) via the command line and execute the object file, the output is</p>
  <pre><code>Total memory allocated: 0
  Total memory freed: 0
  Total memory usage: 0
  
  Total memory allocated: 4
  Total memory freed: 0
  Total memory usage: 4
  
  Total memory allocated: 4
  Total memory freed: 0
  Total memory usage: 4
  </code></pre>
  <p>indicating a memory leak. Now, in VScode, I put a breakpoint in the overriden delete operator to see if it visited the function. Sure enough, in VScode, using g++20 as well, It <em>did</em> visit the function. The output in the VScode terminal was this:</p>
  <pre><code>Total memory allocated: 0
  Total memory freed: 0
  Total memory usage: 0
  
  Total memory allocated: 4
  Total memory freed: 0
  Total memory usage: 4
  
  4 added to total freed 
  Total memory allocated: 4
  Total memory freed: 4
  Total memory usage: 0
  </code></pre>
  <p>I've run into stuff like this before, but never this blatant. Could someone please shed light on what may be going on here?</p>