What are pinned objects?

后端 未结 7 772
遇见更好的自我
遇见更好的自我 2020-11-30 05:19

I am trying to find a memory leak using ants memory profiler, and I\'ve encountered in a new term:

Pinned objects.

Can some one give me a good & simple e

7条回答
  •  醉酒成梦
    2020-11-30 06:11

    Pinned objects are used when communicating with non-managed code. In managed code the garbage collector is free to move memory blocks around, as it knows about all references to the memory block and can update those accordingly.

    When communicating with non-managed code (e.g. Win-API) pointers to data or buffers are often passed as argument. If the garbage collector was free to move that data, the pointers would suddenly become invalid. As the pointer is transferred to unmanaged code, it is not possible for the GC to update the pointer - or even know of where it is used. To prevent memory moving and make sure that the data stays in the place known by the unmanaged code's pointer the object can be pinned.

提交回复
热议问题