来自go的COM调用通过GC收集了其数据,将已用内存清零

I have a go program that executes a WMI query then converts the data back into go-land data structures (using the method here). Every so often, go's GC comes along and nukes some seemingly random parts of memory to 0s, causing horrible breakage.

I am trying to figure out what exactly is causing this problem, and the next step, I believe, is to understand what happens during the COM call. My current understanding is:

  1. call into COM with the WMI query from a process
  2. the OS executes the query and writes the results into some memory location owned by the process
  3. that location is returned from the COM call, which I can then access and serialize

Is this about what happens? How does Windows choose that memory location such that it doesn't overwrite existing data?

Every COM object is reference counted with AddRef() and Release(). Perhaps you need an extra AddRef() to keep it around longer.

I see from the sample code that there are a lot of defered Release calls. This is fine because we want the objects released at the end of main. In your program you might want to put off Release even longer (but, I don't know go or exactly what defer does)