Add memory management code
authorJeesun Kim <iamjs.kim@samsung.com>
Wed, 12 Apr 2017 08:36:37 +0000 (17:36 +0900)
committerJeesun Kim <iamjs.kim@samsung.com>
Thu, 13 Apr 2017 02:15:24 +0000 (11:15 +0900)
Change-Id: I073aba1aa601eb2d35ebb67c8866cb1dc16f1d56

src/Tizen.Pims.Calendar/Tizen.Pims.Calendar/CalendarList.cs
src/Tizen.Pims.Calendar/Tizen.Pims.Calendar/CalendarRecord.cs
src/Tizen.Pims.Calendar/Tizen.Pims.Calendar/CalendarViews.cs

index 91e6f33..875d643 100644 (file)
@@ -28,11 +28,16 @@ namespace Tizen.Pims.Calendar
     /// </summary>
     public class CalendarList:IDisposable
     {
+        private Int64 _memoryPressure = 20;
         internal int _count = -1;
         internal IntPtr _listHandle;
+
         internal CalendarList(IntPtr handle)
         {
             _listHandle = handle;
+
+            _memoryPressure += this.Count * CalendarViews.AverageSizeOfRecord;
+            GC.AddMemoryPressure(_memoryPressure);
         }
 
         /// <summary>
@@ -46,6 +51,7 @@ namespace Tizen.Pims.Calendar
                 Log.Error(Globals.LogTag, "CalendarList Failed with error " + error);
                 throw CalendarErrorFactory.GetException(error);
             }
+            GC.AddMemoryPressure(_memoryPressure);
         }
 
         ~CalendarList()
@@ -90,6 +96,7 @@ namespace Tizen.Pims.Calendar
                     throw CalendarErrorFactory.GetException(error);
                 }
                 disposedValue = true;
+                GC.RemoveMemoryPressure(_memoryPressure);
             }
         }
 
@@ -113,6 +120,7 @@ namespace Tizen.Pims.Calendar
             }
             record._disposedValue = true;
             _count = -1;
+            _memoryPressure += CalendarViews.AverageSizeOfRecord;
         }
 
         /// <summary>
@@ -129,6 +137,7 @@ namespace Tizen.Pims.Calendar
             }
             record._disposedValue = false;
             _count = -1;
+            _memoryPressure -= CalendarViews.AverageSizeOfRecord;
         }
 
         /// <summary>
index 7c4eec3..64234e7 100644 (file)
@@ -30,6 +30,7 @@ namespace Tizen.Pims.Calendar
     {
         internal string _uri;
         internal uint _id;
+        private Int64 _memoryPressure = CalendarViews.AverageSizeOfRecord;
         internal IntPtr _recordHandle;
 
         internal CalendarRecord(IntPtr handle)
@@ -44,6 +45,7 @@ namespace Tizen.Pims.Calendar
                 throw CalendarErrorFactory.GetException(error);
             }
             _uri = Marshal.PtrToStringAnsi(viewUri);
+            GC.AddMemoryPressure(_memoryPressure);
         }
 
         internal CalendarRecord(IntPtr handle, bool disposedValue)
@@ -59,6 +61,8 @@ namespace Tizen.Pims.Calendar
                 throw CalendarErrorFactory.GetException(error);
             }
             _uri = Marshal.PtrToStringAnsi(viewUri);
+            if (!_disposedValue)
+                GC.AddMemoryPressure(_memoryPressure);
         }
 
         internal CalendarRecord(IntPtr handle, int id)
@@ -74,6 +78,7 @@ namespace Tizen.Pims.Calendar
                 throw CalendarErrorFactory.GetException(error);
             }
             _uri = Marshal.PtrToStringAnsi(viewUri);
+            GC.AddMemoryPressure(_memoryPressure);
         }
 
         /// <summary>
@@ -90,6 +95,7 @@ namespace Tizen.Pims.Calendar
                 throw CalendarErrorFactory.GetException(error);
             }
             _uri = viewUri;
+            GC.AddMemoryPressure(_memoryPressure);
         }
 
         ~CalendarRecord()
@@ -113,6 +119,7 @@ namespace Tizen.Pims.Calendar
                     throw CalendarErrorFactory.GetException(error);
                 }
                 _disposedValue = true;
+                GC.RemoveMemoryPressure(_memoryPressure);
             }
         }
 
index cb10cd6..2750c79 100644 (file)
@@ -328,6 +328,8 @@ namespace Tizen.Pims.Calendar
             ExtendedValue        = (ViewExtended|DataTypeString) + 4,
         }
 
+        internal const uint AverageSizeOfRecord = 56; ///average size
+
         /// <summary>
         /// </summary>
         public class Book