Пример #1
0
        private void createButton_Click(object sender, EventArgs e)
        {
            if (_bag == null)
            {
                _bag = new Bag();

                byte[] byteArray = new byte[100000];
                for (int i = 0; i < byteArray.Length; i++)
                {
                    byteArray[i] = 1;
                }
                _bag.Items.Add(byteArray);

                outPutListBox.Items.Add("Create Bag: GC Memory (bytes): " + GC.GetTotalMemory(true).ToString());
                outPutListBox.Items.Add("");
            }

            if (_myBag == null)
            {
                _myBag = new MyBag();
                outPutListBox.Items.Add("Create MyBag: GC Memory (bytes): " + GC.GetTotalMemory(true).ToString());
                outPutListBox.Items.Add("");
                _myBag.s1 += "This is the sentence for string one.";
                outPutListBox.Items.Add("After s1 allocation: GC Memory (bytes): " + GC.GetTotalMemory(true).ToString());
                outPutListBox.Items.Add("");
                _myBag.s2 += "This is the sentence for string two.";
                outPutListBox.Items.Add("After s2 allocation: GC Memory (bytes): " + GC.GetTotalMemory(true).ToString());
                outPutListBox.Items.Add("");
                _myBag.s3 += "This is the sentence for string three.";
                outPutListBox.Items.Add("After s3 allocation: GC Memory (bytes): " + GC.GetTotalMemory(true).ToString());
            }
        }
Пример #2
0
        private void destroyButton_Click(object sender, EventArgs e)
        {
            if (_bag != null)
            {
                _bag = null;

                outPutListBox.Items.Add("Destroy Bag: GC Memory bytes: " + GC.GetTotalMemory(true).ToString());
                outPutListBox.Items.Add("");
            }

            if (_myBag != null)
            {
                _myBag = null;

                outPutListBox.Items.Add("Destroy MyBag: GC Memory bytes: " + GC.GetTotalMemory(true).ToString());
                outPutListBox.Items.Add("");
            }
        }