Quantcast
Channel: Common Language Runtime Internals and Architecture forum
Viewing all articles
Browse latest Browse all 1710

GC and pinned objects

$
0
0

Hi,

in my own VB project, I'm referencing a 3rd party assembly. I'm facing a strange exception that occurs randomly and that I've narrowed down in the past two days using Windbg. It turned to be a garbage collection issue - probably. That means, an object is moved by the GC while an unmanged function is writing to one of the fields of the object.

Normally, the object or one of it's fields has to be pinned to avoid this problem. As it's a 3rd party assembly, I can look at it's IL code only. It shows that the objectis being pinned. Therefore, I'm surprised that the problem occurs at all.

The method in question that I call from my VB code contains this local declaration:

valuetype TypeName* modreq([mscorlib]System.Runtime.CompilerServices.IsVolatile) pinned modreq([mscorlib]System.Runtime.CompilerServices.IsVolatile) V_3)

And these lines assign the address of one of the fields of the object to the local variable:

  IL_0000:  ldarg.0
  IL_0001:  ldflda     valuetype TypeName ClassName::FieldName
  IL_0006:  stloc.3

Afterwards, this local variable (V_3) is passed to the unmanged function. I expect that, during the unmanaged function call, the object can not be moved because of the "pinned" keyword in the declaration line. Is my assumption wrong?


Armin


Viewing all articles
Browse latest Browse all 1710

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>