[Mono.Data.Sqlite] Fix a MonoTouch memory leak
authorRolf Bjarne Kvinge <rolf@xamarin.com>
Tue, 8 Nov 2011 22:59:20 +0000 (23:59 +0100)
committerRodrigo Kumpera <kumpera@gmail.com>
Wed, 7 Nov 2012 18:19:00 +0000 (13:19 -0500)
Ensure SQLite3's GCHandle is freed when Close is called instead of Dispose.
Also make SQLiteConnection's Dispose call SQlite3's Dispose to ensure we free
the GCHandle in all cases.

mcs/class/Mono.Data.Sqlite/Mono.Data.Sqlite_2.0/SQLite3.cs
mcs/class/Mono.Data.Sqlite/Mono.Data.Sqlite_2.0/SQLiteConnection.cs

index 00589e5605f5d80a65e6a2158bb2e0d61cd12e61..82a40ed6c8a1efc6c0a95ab55b5e7884ca7e9b94 100644 (file)
@@ -49,10 +49,6 @@ namespace Mono.Data.Sqlite
     {\r
       if (bDisposing)\r
         Close();\r
-#if MONOTOUCH\r
-      if (gch.IsAllocated)\r
-        gch.Free ();\r
-#endif\r
     }\r
 \r
     // It isn't necessary to cleanup any functions we've registered.  If the connection\r
@@ -73,6 +69,10 @@ namespace Mono.Data.Sqlite
       }\r
 \r
       _sql = null;\r
+#if MONOTOUCH\r
+      if (gch.IsAllocated)\r
+        gch.Free ();\r
+#endif\r
     }\r
 \r
     internal override void Cancel()\r
index d1560c3103cfc9fb341389517bd8cf1155218b0b..961184bb0d7febfc94023cb7fd00418941927d9f 100644 (file)
@@ -304,6 +304,9 @@ namespace Mono.Data.Sqlite
     {\r
       base.Dispose(disposing);\r
 \r
+      if (_sql != null)\r
+        _sql.Dispose ();\r
+\r
       if (disposing)\r
         Close();\r
     }\r