Java Code Examples for android.database.sqlite.SQLiteDatabase#releaseMemory()

The following examples show how to use android.database.sqlite.SQLiteDatabase#releaseMemory() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ActivityThread.java    From AndroidComponentPlugin with Apache License 2.0 6 votes vote down vote up
final void handleLowMemory() {
    ArrayList<ComponentCallbacks2> callbacks;

    synchronized (mPackages) {
        callbacks = collectComponentCallbacksLocked(true, null);
    }

    final int N = callbacks.size();
    for (int i=0; i<N; i++) {
        callbacks.get(i).onLowMemory();
    }

    // Ask SQLite to free up as much memory as it can, mostly from its page caches.
    if (Process.myUid() != Process.SYSTEM_UID) {
        int sqliteReleased = SQLiteDatabase.releaseMemory();
        EventLog.writeEvent(SQLITE_MEM_RELEASED_EVENT_LOG_TAG, sqliteReleased);
    }

    // Ask graphics to free up as much as possible (font/image caches)
    Canvas.freeCaches();

    // Ask text layout engine to free also as much as possible
    Canvas.freeTextLayoutCaches();

    BinderInternal.forceGc("mem");
}
 
Example 2
Source File: ActivityThread.java    From AndroidComponentPlugin with Apache License 2.0 6 votes vote down vote up
final void handleLowMemory() {
    ArrayList<ComponentCallbacks2> callbacks;

    synchronized (mPackages) {
        callbacks = collectComponentCallbacksLocked(true, null);
    }

    final int N = callbacks.size();
    for (int i=0; i<N; i++) {
        callbacks.get(i).onLowMemory();
    }

    // Ask SQLite to free up as much memory as it can, mostly from its page caches.
    if (Process.myUid() != Process.SYSTEM_UID) {
        int sqliteReleased = SQLiteDatabase.releaseMemory();
        EventLog.writeEvent(SQLITE_MEM_RELEASED_EVENT_LOG_TAG, sqliteReleased);
    }

    // Ask graphics to free up as much as possible (font/image caches)
    Canvas.freeCaches();

    BinderInternal.forceGc("mem");
}
 
Example 3
Source File: Launcher.java    From LaunchEnr with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onTrimMemory(int level) {
    super.onTrimMemory(level);
    if (level >= ComponentCallbacks2.TRIM_MEMORY_UI_HIDDEN) {
        // The widget preview db can result in holding onto over
        // 3MB of memory for caching which isn't necessary.
        SQLiteDatabase.releaseMemory();

        // This clears all widget bitmaps from the widget tray
        // TODO(hyunyoungs)
    }
    if (mLauncherCallbacks != null) {
        mLauncherCallbacks.onTrimMemory(level);
    }
}
 
Example 4
Source File: TrustDB.java    From trust with Apache License 2.0 5 votes vote down vote up
private synchronized boolean tryClose() {
    if (mDB != null && mDB.isOpen()) {
        mDB.close();
        SQLiteDatabase.releaseMemory();
    }
    // Log.d(mContext.getPackageName(), "DB close");

    return mDB == null || !mDB.isOpen();
}
 
Example 5
Source File: LiteOrm.java    From android-lite-orm with Apache License 2.0 2 votes vote down vote up
/**
 * Attempts to release memory that SQLite holds but does not require to
 * operate properly. Typically this memory will come from the page cache.
 *
 * @return the number of bytes actually released
 */
public static int releaseMemory() {
    return SQLiteDatabase.releaseMemory();
}