本文介绍了有关GC的基本问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

using System;

class Calci
{

    public int Add(int a, int b)
    {

        return (a + b);

    }

    public int Sub(int a, int b)
    {

        return (a - b);

    }

    public int Multi(int a, int b)
    {

        return (a * b);

    }

    public int Divide(int a, int b)
    {

        return (a / b);

    }

}



class GCExample3
{

    public static void Main(string[] args)
    {

        Calci oCalci = new Calci();

        Console.WriteLine("Calci object is now on " + GC.GetGeneration(oCalci) + " Generation");
        Console.WriteLine("call to GC.Collect(0):");
        GC.Collect(0);
        Console.WriteLine("Garbage Collection Occured in 0th Generation:" + GC.CollectionCount(0));
        Console.WriteLine(oCalci.Add(9, 0));
        Console.ReadLine();
    }

}



输出:



output :

Calci object is now on 0 Generation
 call to GC.Collect(0):
Garbage Collection Occured in 0th Generation:1
9


我的问题是:
如果我的calci对象在第0代中被垃圾回收,那么之后它如何调用calci类的方法?


My question is that:
If my calci object is garbage collected in 0th generation then how after that it calls to methods of calci class?

推荐答案



这篇关于有关GC的基本问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 19:19
查看更多