It is surprisingly difficult to distinguish between heaps and stack objects (which is intentional because .NET wants to hide this information from programmers).
One approach you can take is to compare the default default address hash codes in the marked objects and watch them keep changing ( demo ):
static object MakeBoxed() {
int n = 5;
object a = n;
return a;
}
public static void Main() {
for (int i = 0 ; i != 10 ; i++) {
object a = MakeBoxed();
Console.WriteLine(RuntimeHelpers.GetHashCode(a));
}
}
, MakeBoxed, , MakeBoxed . , Main, , (- ).