OSDN Git Service

ドキュメントをクリアしたときにメモリーを開放するようにした
authortest <test@yahoo.co.jp>
Tue, 5 Jan 2021 15:40:29 +0000 (00:40 +0900)
committertest <test@yahoo.co.jp>
Tue, 5 Jan 2021 15:40:29 +0000 (00:40 +0900)
Core/Document.cs
Core/GapBuffer.cs
Core/StringBuffer.cs
WPF/Test/MainWindow.xaml.cs

index da7b6b0..dfbf8b3 100644 (file)
@@ -1116,6 +1116,8 @@ namespace FooEditEngine
         public void Clear()
         {
             this.buffer.Clear();
+            System.Runtime.GCSettings.LargeObjectHeapCompactionMode = System.Runtime.GCLargeObjectHeapCompactionMode.CompactOnce;
+            GC.Collect();
             this.Dirty = false;
         }
 
index 22941ce..e47a477 100644 (file)
@@ -34,7 +34,7 @@ namespace Slusser.Collections.Generic
        {
                #region Fields
 
-               private const int MIN_CAPACITY = 4;
+               private const int MIN_CAPACITY = 128;
                
                private T[] _buffer;
                private int _gapStart;
@@ -710,7 +710,7 @@ namespace Slusser.Collections.Generic
                        if (required > (this._gapEnd - this._gapStart))
                        {
                                // Calculate a new size (double the size necessary)
-                               int newCapacity = (Count + required) * 2;
+                               int newCapacity = Count + required + MIN_CAPACITY;
                                if (newCapacity < MIN_CAPACITY)
                                        newCapacity = MIN_CAPACITY;
 
index 175f516..a364cee 100644 (file)
@@ -234,6 +234,7 @@ namespace FooEditEngine
         internal void Clear()
         {
             this.buf.Clear();
+            this.buf.TrimExcess();
             this.Update(this, new DocumentUpdateEventArgs(UpdateType.Clear, 0, this.buf.Count, 0));
         }
 
index 468242b..98bf3b9 100644 (file)
@@ -124,7 +124,11 @@ namespace Test
             if (result == true)
             {
                 this.fooTextBox.IsEnabled = false;
-                await this.fooTextBox.LoadFileAsync(ofd.FileName, Encoding.Default,this.cancleTokenSrc);
+                System.IO.FileStream file = System.IO.File.Open(ofd.FileName,System.IO.FileMode.Open);
+                System.IO.StreamReader sr = new System.IO.StreamReader(file, Encoding.Default);
+                await this.fooTextBox.Document.LoadAsync(sr, this.cancleTokenSrc, (int)file.Length);
+                sr.Close();
+                file.Close();
                 this.fooTextBox.IsEnabled = true;
                 this.fooTextBox.Refresh();
             }