Example usage for java.lang System gc

List of usage examples for java.lang System gc

Introduction

In this page you can find the example usage for java.lang System gc.

Prototype

public static void gc() 

Source Link

Document

Runs the garbage collector in the Java Virtual Machine.

Usage

From source file:Main.java

public static void forceGCandWait() {
    Object obj = new Object();
    WeakReference ref = new WeakReference<>(obj);
    obj = null;/*from w ww .j  av a 2  s .c  o  m*/

    System.gc();
    System.runFinalization();
    /** wait for garbage collector finished*/
    while (ref.get() != null)
        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
        } //System.gc();
}

From source file:Main.java

public static void recycleBitmap(Bitmap mBitmap) {
    if (mBitmap != null && !mBitmap.isRecycled()) {
        mBitmap.recycle();/* ww w.ja v  a 2 s  .c om*/
        mBitmap = null;
        System.gc();
        System.runFinalization();
        System.gc();
    }
}

From source file:Main.java

public static void recycleBitmap(Bitmap decodeFile) {
    if (decodeFile != null && !decodeFile.isRecycled()) {
        decodeFile.recycle();/*www.j av a 2  s.co  m*/
        decodeFile = null;
        System.gc();
    }
}

From source file:Main.java

public static void setOjectsNull(Object[] objects) {
    if (objects != null) {
        for (int i = 0; i < objects.length; i++) {
            objects[i] = null;/*from  w  w w  .  j  ava 2  s  .c  om*/
        }
    }
    objects = null;
    System.gc();
}

From source file:Main.java

public static void recycleBitmap(Bitmap bitmap) {
    if (bitmap != null && !bitmap.isRecycled()) {
        bitmap.recycle();/*  w w w.ja v a 2s . c o  m*/
        bitmap = null;
        System.gc();
    }
}

From source file:Main.java

/**
 * Clears all Bitmap data, that is, recycles the Bitmap and 
 * triggers the garbage collection./* ww  w .j a v  a  2s.  c o  m*/
 * 
 * @param bm
 */
public static void clearBitmap(Bitmap bm) {
    bm.recycle();
    System.gc();
}

From source file:ejp.examples.InDepthExample.java

public static void main(String[] args) throws DatabaseException, ClassNotFoundException {
    DatabaseManager dbm = DatabaseManager.getDatabaseManager("ejp_hsql");
    CreateDatabase.createHSQLDatabase(dbm);

    //dbm = DatabaseManager.getDatabaseManager("ejp", 10, getDbcpDataSource());
    //dbm = DatabaseManager.getDatabaseManager("ejp", 10,
    //      "com.mysql.jdbc.Driver", "jdbc:mysql://localhost/ejp_example", "user", "passwd");

    for (int i = 0; i < 1; i++) {
        new InDepthExample(dbm);
        System.out.println("count=" + (i + 1));
        System.gc();
    }//  w w  w. j a v a2 s. co m
}

From source file:Main.java

public static final void recycle(Bitmap bitmap) {
    System.out.println("==recycle==");
    if (bitmap != null && !bitmap.isRecycled()) {
        System.out.println("--true");
        bitmap.recycle();//from w  ww  .  ja va  2  s  .  c om
        bitmap = null;
        System.gc();
    }
}

From source file:Main.java

/**
 * Garbage recycle//from  w  w w. j a v a 2s.co  m
 * 
 * @throws
 */
public static void recycle(Bitmap bitmap) {
    if (bitmap != null && !bitmap.isRecycled()) {
        // recycle bitmap and assign to null
        bitmap.recycle();
        bitmap = null;
    }
    System.gc();
}

From source file:Main.java

public static Bitmap createBitmap(int width, int height, Bitmap.Config config) {
    Bitmap bitmap = null;//from  ww  w .j  a  va  2 s .  c  o  m
    try {
        bitmap = Bitmap.createBitmap(width, height, config);
    } catch (OutOfMemoryError e) {
        while (bitmap == null) {
            System.gc();
            System.runFinalization();
            bitmap = createBitmap(width, height, config);
        }
    }
    return bitmap;
}