[STT/TTS] Fix desctructor to call dispose (#596)
authorSooyeon Kim <syeonsyeon@gmail.com>
Thu, 6 Dec 2018 06:09:20 +0000 (15:09 +0900)
committerSeungkeun Lee <sngn.lee@samsung.com>
Thu, 6 Dec 2018 06:09:20 +0000 (15:09 +0900)
Signed-off-by: sooyeon.kim <sooyeon.kim@samsung.com>
src/Tizen.Uix.Stt/Tizen.Uix.Stt/SttClient.cs [changed mode: 0755->0644]
src/Tizen.Uix.Tts/Tizen.Uix.Tts/TtsClient.cs [changed mode: 0755->0644]

old mode 100755 (executable)
new mode 100644 (file)
index c057a86..76f70ca
@@ -364,6 +364,14 @@ namespace Tizen.Uix.Stt
         }
 
         /// <summary>
+        /// Destructor to destroy a STT instance.
+        /// </summary>
+        ~SttClient()
+        {
+            Dispose(false);
+        }
+
+        /// <summary>
         /// Event to be invoked when the recognition is done.
         /// </summary>
         /// <since_tizen> 3 </since_tizen>
@@ -1494,6 +1502,7 @@ namespace Tizen.Uix.Stt
         public void Dispose()
         {
             Dispose(true);
+            GC.SuppressFinalize(this);
         }
 
         /// <summary>
@@ -1507,19 +1516,20 @@ namespace Tizen.Uix.Stt
         {
             if (!disposedValue)
             {
-                if (disposing)
-                {
-                    lock (thisLock)
-                    {
-                        SttError error = SttDestroy(_handle);
-                        if (error != SttError.None)
-                        {
-                            Log.Error(LogTag, "Destroy Failed with error " + error);
-                        }
-                    }
-                }
-
-                disposedValue = true;
+                               lock (thisLock)
+                               {
+                                       if (_handle != IntPtr.Zero)
+                                       {
+                                               SttError error = SttDestroy(_handle);
+                                               if (error != SttError.None)
+                                               {
+                                                       Log.Error(LogTag, "Destroy Failed with error " + error);
+                                               }
+                                               _handle = IntPtr.Zero;
+                                       }
+                               }
+
+                               disposedValue = true;
             }
         }
     }
old mode 100755 (executable)
new mode 100644 (file)
index 7dab0ae..6a53f5c
@@ -240,6 +240,14 @@ namespace Tizen.Uix.Tts
         }
 
         /// <summary>
+        /// Destructor to destroy TtsClient handle.
+        /// </summary>
+        ~TtsClient()
+        {
+            Dispose(false);
+        }
+
+        /// <summary>
         /// Event to be invoked when TTS state changes.
         /// </summary>
         /// <since_tizen> 3 </since_tizen>
@@ -1041,6 +1049,7 @@ namespace Tizen.Uix.Tts
         public void Dispose()
         {
             Dispose(true);
+            GC.SuppressFinalize(this);
         }
 
         /// <summary>
@@ -1053,20 +1062,21 @@ namespace Tizen.Uix.Tts
         protected virtual void Dispose(bool disposing)
         {
             if (!disposedValue)
-            {
-                if (disposing)
-                {
-                    lock (thisLock)
-                    {
-                        TtsError error = TtsDestroy(_handle);
-                        if (error != TtsError.None)
-                        {
-                            Log.Error(LogTag, "Destroy Failed with error " + error);
-                        }
-                    }
-                }
-
-                disposedValue = true;
+                       {
+                               lock (thisLock)
+                               {
+                                       if (_handle != IntPtr.Zero)
+                                       {
+                                               TtsError error = TtsDestroy(_handle);
+                                               if (error != TtsError.None)
+                                               {
+                                                       Log.Error(LogTag, "Destroy Failed with error " + error);
+                                               }
+                                               _handle = IntPtr.Zero;
+                                       }
+                               }
+
+                               disposedValue = true;
             }
         }
     }