Home | History | Annotate | Download | only in src
      1 /*
      2  * Copyright (C) 2009 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 public class Main {
     18     Bitmap mBitmap1, mBitmap2, mBitmap3, mBitmap4;
     19 
     20     public static void sleep(int ms) {
     21         try {
     22             Thread.sleep(ms);
     23         } catch (InterruptedException ie) {
     24             System.err.println("sleep interrupted");
     25         }
     26     }
     27 
     28     public static void main(String args[]) {
     29         System.out.println("start");
     30 
     31         Main main = new Main();
     32         main.run();
     33 
     34         sleep(1000);
     35         System.out.println("done");
     36     }
     37 
     38     public void run() {
     39         createBitmaps();
     40 
     41         System.gc();
     42         sleep(250);
     43 
     44         mBitmap2.drawAt(0, 0);
     45 
     46         System.out.println("nulling 1");
     47         mBitmap1 = null;
     48         System.gc();
     49         sleep(500);
     50 
     51         System.out.println("nulling 2");
     52         mBitmap2 = null;
     53         System.gc();
     54         sleep(500);
     55 
     56         System.out.println("nulling 3");
     57         mBitmap3 = null;
     58         System.gc();
     59         sleep(500);
     60 
     61         System.out.println("nulling 4");
     62         mBitmap4 = null;
     63         System.gc();
     64         sleep(500);
     65 
     66         Bitmap.shutDown();
     67     }
     68 
     69     /*
     70      * Create bitmaps.
     71      *
     72      * bitmap1 is 10x10 and unique
     73      * bitmap2 and bitmap3 are 20x20 and share the same storage.
     74      * bitmap4 is just another reference to bitmap3
     75      *
     76      * When we return there should be no local refs lurking on the stack.
     77      */
     78     public void createBitmaps() {
     79         Bitmap.NativeWrapper dataA = Bitmap.allocNativeStorage(10, 10);
     80         Bitmap.NativeWrapper dataB = Bitmap.allocNativeStorage(20, 20);
     81         mBitmap1 = new Bitmap("one", 10, 10, dataA);
     82         mBitmap2 = new Bitmap("two", 20, 20, dataB);
     83         mBitmap3 = mBitmap4 = new Bitmap("three/four", 20, 20, dataB);
     84     }
     85 }
     86 
     87