public
anonymous / gist:4263527
Created

checking if fixed statement influences GC generations

  • Download Gist
gistfile1.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
using System;
 
namespace ConsoleApplication1
{
public class Point
{
public int x;
public int y;
}
 
internal class Program
{
private static unsafe void Main(string[] args)
{
var point = new Point();
fixed (void* p = &point.x)
{
Console.WriteLine("inside fixed: object is in Gen{0}", GC.GetGeneration(point));
GC.Collect();
Console.WriteLine("inside fixed: after GC object is in Gen{0}", GC.GetGeneration(point));
}
Console.WriteLine("outside fixed: object is in Gen{0}", GC.GetGeneration(point));
GC.Collect();
Console.WriteLine("outside fixed: after GC object is in Gen{0}", GC.GetGeneration(point));
 
// Output:
//
//inside fixed: object is in Gen0
//inside fixed: after GC object is in Gen1
//outside fixed: object is in Gen1
//outside fixed: after GC object is in Gen2
}
}
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.