jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 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 | |
Mathieu Chartier | 7befd0e | 2014-02-03 17:48:41 -0800 | [diff] [blame] | 41 | Runtime.getRuntime().gc(); |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 42 | sleep(250); |
| 43 | |
| 44 | mBitmap2.drawAt(0, 0); |
| 45 | |
| 46 | System.out.println("nulling 1"); |
| 47 | mBitmap1 = null; |
Mathieu Chartier | 7befd0e | 2014-02-03 17:48:41 -0800 | [diff] [blame] | 48 | Runtime.getRuntime().gc(); |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 49 | sleep(500); |
| 50 | |
| 51 | System.out.println("nulling 2"); |
| 52 | mBitmap2 = null; |
Mathieu Chartier | 7befd0e | 2014-02-03 17:48:41 -0800 | [diff] [blame] | 53 | Runtime.getRuntime().gc(); |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 54 | sleep(500); |
| 55 | |
| 56 | System.out.println("nulling 3"); |
| 57 | mBitmap3 = null; |
Mathieu Chartier | 7befd0e | 2014-02-03 17:48:41 -0800 | [diff] [blame] | 58 | Runtime.getRuntime().gc(); |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 59 | sleep(500); |
| 60 | |
| 61 | System.out.println("nulling 4"); |
| 62 | mBitmap4 = null; |
Mathieu Chartier | 7befd0e | 2014-02-03 17:48:41 -0800 | [diff] [blame] | 63 | Runtime.getRuntime().gc(); |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 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 | } |