[f-spot/taglib-metadata: 3/3] More resource disposal.



commit 3cb557a3b558b623ce839eb102d368cbbce08b10
Author: Ruben Vermeersch <ruben savanne be>
Date:   Sun May 16 12:28:38 2010 +0200

    More resource disposal.

 src/Imaging/JpegFile.cs               |    4 ++++
 src/Utils/GIOTagLibFileAbstraction.cs |   12 +++++++++++-
 2 files changed, 15 insertions(+), 1 deletions(-)
---
diff --git a/src/Imaging/JpegFile.cs b/src/Imaging/JpegFile.cs
index 6f0415c..f24ec04 100644
--- a/src/Imaging/JpegFile.cs
+++ b/src/Imaging/JpegFile.cs
@@ -28,6 +28,10 @@ namespace FSpot {
 		{
 		}
 
+		~JpegFile () {
+			metadata_file.Dispose ();
+		}
+
 		public override Cms.Profile GetProfile ()
 		{
 			return null;
diff --git a/src/Utils/GIOTagLibFileAbstraction.cs b/src/Utils/GIOTagLibFileAbstraction.cs
index 46a5626..b975fee 100644
--- a/src/Utils/GIOTagLibFileAbstraction.cs
+++ b/src/Utils/GIOTagLibFileAbstraction.cs
@@ -6,6 +6,8 @@ namespace FSpot.Utils
 {
     public sealed class GIOTagLibFileAbstraction : TagLib.File.IFileAbstraction
     {
+        private FileInputStream gio_stream;
+
         public string Name {
             get {
                 return Uri.ToString ();
@@ -18,7 +20,13 @@ namespace FSpot.Utils
         public Uri Uri { get; set; }
 
         public Stream ReadStream {
-            get { return new GioStream (FileFactory.NewForUri(Uri).Read (null)); }
+            get {
+                if (gio_stream == null) {
+                    var file = FileFactory.NewForUri(Uri);
+                    gio_stream = file.Read (null);
+                }
+                return new GioStream (gio_stream); 
+            }
         }
 
         public Stream WriteStream {
@@ -28,6 +36,8 @@ namespace FSpot.Utils
         public void CloseStream (Stream stream)
         {
             stream.Close ();
+            gio_stream.Dispose ();
+            gio_stream = null;
         }
     }
 }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]