コード例 #1
0
        public void GCCallbackTest()
        {
            bool     collectedTextView = false;
            TextView textView          = new TextViewWithGCCallback(delegate { collectedTextView = true; });

            textView = null;
            GarbageCollect();
            Assert.IsTrue(collectedTextView);
        }
コード例 #2
0
 // using a method to ensure the local variables can be garbage collected after the method returns
 void DocumentDoesNotHoldReferenceToLineMargin_CreateMargin(TextDocument textDocument, Action finalizeAction)
 {
     TextView textView = new TextViewWithGCCallback(finalizeAction)
     {
         Document = textDocument
     };
     LineNumberMargin margin = new LineNumberMargin()
     {
         TextView = textView
     };
 }
コード例 #3
0
        public void DocumentDoesNotHoldReferenceToTextView()
        {
            bool collectedTextView = false;
            TextDocument textDocument = new TextDocument();
            Assert.AreEqual(0, textDocument.LineTrackers.Count);

            TextView textView = new TextViewWithGCCallback(delegate { collectedTextView = true; });
            textView.Document = textDocument;
            Assert.AreEqual(1, textDocument.LineTrackers.Count);
            textView = null;

            GarbageCollect();
            Assert.IsTrue(collectedTextView);
            // document cannot immediately clear the line tracker
            Assert.AreEqual(1, textDocument.LineTrackers.Count);

            // but it should clear it on the next change
            textDocument.Insert(0, "a");
            Assert.AreEqual(0, textDocument.LineTrackers.Count);
        }
コード例 #4
0
        public void DocumentDoesNotHoldReferenceToTextView()
        {
            bool         collectedTextView = false;
            TextDocument textDocument      = new TextDocument();

            Assert.AreEqual(0, textDocument.LineTrackers.Count);

            TextView textView = new TextViewWithGCCallback(delegate { collectedTextView = true; });

            textView.Document = textDocument;
            Assert.AreEqual(1, textDocument.LineTrackers.Count);
            textView = null;

            GarbageCollect();
            Assert.IsTrue(collectedTextView);
            // document cannot immediately clear the line tracker
            Assert.AreEqual(1, textDocument.LineTrackers.Count);

            // but it should clear it on the next change
            textDocument.Insert(0, "a");
            Assert.AreEqual(0, textDocument.LineTrackers.Count);
        }
コード例 #5
0
 public void GCCallbackTest()
 {
     bool collectedTextView = false;
     TextView textView = new TextViewWithGCCallback(delegate { collectedTextView = true; });
     textView = null;
     GarbageCollect();
     Assert.IsTrue(collectedTextView);
 }
コード例 #6
0
 // using a method to ensure the local variables can be garbage collected after the method returns
 void DocumentDoesNotHoldReferenceToLineMargin_CreateMargin(TextDocument textDocument, Action finalizeAction)
 {
     TextView textView = new TextViewWithGCCallback(finalizeAction) {
         Document = textDocument
     };
     LineNumberMargin margin = new LineNumberMargin() {
         TextView = textView
     };
 }