Modified flushing memory logic
[platform/core/appfw/app-core.git] / src / base / appcore_base.c
index 1754f07..dfc6f2c 100644 (file)
@@ -791,7 +791,9 @@ static gboolean __flush_memory(gpointer data)
 {
        int suspend = APPCORE_BASE_SUSPENDED_STATE_WILL_ENTER_SUSPEND;
 
-       appcore_base_flush_memory();
+       if (__context.ops.trim_memory)
+               __context.ops.trim_memory(__context.data);
+
        __context.tid = 0;
 
        if (!__context.allowed_bg && !__context.suspended_state) {
@@ -1139,19 +1141,9 @@ EXPORT_API void appcore_base_fini(void)
 
 EXPORT_API int appcore_base_flush_memory(void)
 {
-       int (*sqlite3_free_heap_memory)(int);
-       void (*elm_free_all_cache)(void);
+       if (__context.ops.trim_memory)
+               __context.ops.trim_memory(__context.data);
 
-       elm_free_all_cache = dlsym(RTLD_DEFAULT, "elm_cache_all_flush");
-       if (elm_free_all_cache)
-               elm_free_all_cache();
-
-       sqlite3_free_heap_memory = dlsym(RTLD_DEFAULT,
-                       "sqlite3_release_memory");
-       if (sqlite3_free_heap_memory)
-               sqlite3_free_heap_memory(SQLITE_FLUSH_MAX);
-
-       malloc_trim(0);
        return 0;
 }
 
@@ -1303,6 +1295,20 @@ EXPORT_API void appcore_base_on_unset_event(enum appcore_base_event event)
        }
 }
 
+EXPORT_API int appcore_base_on_trim_memory(void)
+{
+       int (*sqlite3_free_heap_memory)(int);
+
+       sqlite3_free_heap_memory = dlsym(RTLD_DEFAULT,
+                       "sqlite3_release_memory");
+       if (sqlite3_free_heap_memory)
+               sqlite3_free_heap_memory(SQLITE_FLUSH_MAX);
+
+       malloc_trim(0);
+
+       return 0;
+}
+
 EXPORT_API appcore_base_event_h appcore_base_add_event(enum appcore_base_event event,
                appcore_base_event_cb cb, void *data)
 {
@@ -1421,12 +1427,17 @@ static int __on_set_i18n(void *data)
 
 static void __on_set_event(enum appcore_base_event event, void *data)
 {
-       return appcore_base_on_set_event(event);
+       appcore_base_on_set_event(event);
 }
 
 static void __on_unset_event(enum appcore_base_event event, void *data)
 {
-       return appcore_base_on_unset_event(event);
+       appcore_base_on_unset_event(event);
+}
+
+static void __on_trim_memory(void *data)
+{
+       appcore_base_on_trim_memory();
 }
 
 EXPORT_API appcore_base_ops appcore_base_get_default_ops(void)
@@ -1444,6 +1455,7 @@ EXPORT_API appcore_base_ops appcore_base_get_default_ops(void)
        ops.exit = NULL;
        ops.set_event = __on_set_event;
        ops.unset_event = __on_unset_event;
+       ops.trim_memory = __on_trim_memory;
 
        return ops;
 }