Browse Source

Release some of the memory on document close

Equbuxu 3 years ago
parent
commit
cbb5ef0cab

+ 1 - 0
PixiEditor/Models/Controllers/BitmapManager.cs

@@ -120,6 +120,7 @@ namespace PixiEditor.Models.Controllers
 
 
             Documents.Remove(document);
             Documents.Remove(document);
             ActiveDocument = nextIndex >= 0 ? Documents[nextIndex] : null;
             ActiveDocument = nextIndex >= 0 ? Documents[nextIndex] : null;
+            document.DisposeLayerBitmaps();
         }
         }
 
 
         public void ExecuteTool(Coordinates newPosition, bool clickedOnCanvas)
         public void ExecuteTool(Coordinates newPosition, bool clickedOnCanvas)

+ 14 - 0
PixiEditor/Models/DataHolders/Document/Document.Layers.cs

@@ -494,6 +494,20 @@ namespace PixiEditor.Models.DataHolders
             return layer;
             return layer;
         }
         }
 
 
+        public void DisposeLayerBitmaps()
+        {
+            foreach (var layer in layers)
+            {
+                layer.LayerBitmap.Dispose();
+            }
+            referenceLayer?.LayerBitmap.Dispose();
+            previewLayer?.LayerBitmap.Dispose();
+
+            previewLayerRenderer?.Dispose();
+            referenceLayerRenderer?.Dispose();
+            renderer?.Dispose();
+        }
+
         public SKColor GetColorAtPoint(int x, int y)
         public SKColor GetColorAtPoint(int x, int y)
         {
         {
             return Renderer.FinalSurface.GetSRGBPixel(x, y);
             return Renderer.FinalSurface.GetSRGBPixel(x, y);

+ 2 - 0
PixiEditor/Models/Layers/Layer.cs

@@ -505,6 +505,8 @@ namespace PixiEditor.Models.Layers
 
 
         public void ClearCanvas()
         public void ClearCanvas()
         {
         {
+            if (IsReset)
+                return;
             LayerBitmap.SkiaSurface.Canvas.Clear();
             LayerBitmap.SkiaSurface.Canvas.Clear();
             InvokeLayerBitmapChange();
             InvokeLayerBitmapChange();
         }
         }