Prevent from GC regarding callbacks variable.
authorSung-jae Park <nicesj.park@samsung.com>
Mon, 8 May 2017 02:25:33 +0000 (11:25 +0900)
committerChulSeung Kim <charles0.kim@samsung.com>
Thu, 8 Jun 2017 09:34:54 +0000 (18:34 +0900)
Even if we passed callbacks member variable to interop API,
It is released by GC.

C# runtime does not recognize status of the interop API.
So it is able to release the varaibles anytime when it meets
some condition to do that.

To prevent from GC, use the static.
If there is better way to avoid GC, we should consider it again.

Change-Id: I351f89bfc5350ec19e462999d2331e194244d0b5
Signed-off-by: Sung-jae Park <nicesj.park@samsung.com>
TVHome/TVHome.TizenTV/Sniper.cs
TVHome/TVHome.TizenTV/SniperInterOp.cs

index d2477e4758883d48a3ba2230cebb9f26268e7b0b..697ad7f642ee803aa3cabe0f732780cc004db09b 100644 (file)
@@ -13,6 +13,7 @@ namespace CoreApp
         private int imageWidth;
         private int imageHeight;
         public bool SkipUpdateFlag;
+               private static InterOp.SniperCallback callbacks;
 
         public event EventHandler<Event> UpdatedEvent;
         public event EventHandler<Event> AddRemoveEvent;
@@ -166,8 +167,6 @@ namespace CoreApp
 
         public void StartMonitor()
         {
-            InterOp.SniperCallback callbacks;
-
             try
             {
                 callbacks = new InterOp.SniperCallback();
index 88519963d67254ec647e715f298692207b901fa9..ed27a867ebae0f41091beab542b2c37d4258f136 100644 (file)
@@ -5,8 +5,11 @@ namespace CoreApp
 {
     internal static partial class InterOp
     {
+        [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
         public delegate void CallbackAddedRemoved(string appId, string instanceId);
+        [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
         public delegate void CallbackUpdated(string appId, string instanceId, string filename);
+        [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
         public delegate int CallbackSkipUpdate(string appid, string instanceId, string filename);
 
         [StructLayout(LayoutKind.Sequential)]