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
In order to pin objects you can use the fixed keyword:
The fixed statement prevents the garbage collector from relocating a movable variable. The fixed statement is only permitted in an unsafe context.
An example I've seen before is breaking up a long value into bytes so that it can be encoded into a serial key. This was done in an unsafe context in order to get the pointer. Intermittent errors started occurring because garbage collection would happen halfway through the process of getting the individual bytes. The value would get relocated and we were left with half correct bytes, half garbage bytes.
The solution for us was to use the BitConverter class. If you look at the underlying code of the BitConverter class, you will see it uses the fixed keyword to pin the byte array while obtaining the bytes from the variable.