auto import from //depot/cupcake/@136594
diff --git a/tools/aapt/Images.cpp b/tools/aapt/Images.cpp
index edb12ea..0a4c68b 100644
--- a/tools/aapt/Images.cpp
+++ b/tools/aapt/Images.cpp
@@ -332,8 +332,8 @@
     int H = image->height;
     int i, j;
 
-    int maxSizeXDivs = (W / 2 + 1) * sizeof(int32_t);
-    int maxSizeYDivs = (H / 2 + 1) * sizeof(int32_t);
+    int maxSizeXDivs = W * sizeof(int32_t);
+    int maxSizeYDivs = H * sizeof(int32_t);
     int32_t* xDivs = (int32_t*) malloc(maxSizeXDivs);
     int32_t* yDivs = (int32_t*) malloc(maxSizeYDivs);
     uint8_t  numXDivs = 0;
diff --git a/tools/aidl/aidl.cpp b/tools/aidl/aidl.cpp
index dc61567..e248763 100644
--- a/tools/aidl/aidl.cpp
+++ b/tools/aidl/aidl.cpp
@@ -617,7 +617,7 @@
 
     FILE* f = fopen(filename.c_str(), "rb");
     if (f == NULL) {
-        fprintf(stderr, "aidl: can't open preprocessd file: %s\n",
+        fprintf(stderr, "aidl: can't open preprocessed file: %s\n",
                 filename.c_str());
         return 1;
     }
diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/Bridge.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/Bridge.java
index 6abc452d..47a7ec0 100644
--- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/Bridge.java
+++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/Bridge.java
@@ -56,6 +56,7 @@
 import android.view.WindowManager.LayoutParams;
 import android.widget.FrameLayout;
 
+import java.lang.ref.SoftReference;
 import java.lang.reflect.Field;
 import java.lang.reflect.Modifier;
 import java.util.Collection;
@@ -94,14 +95,15 @@
     private final static Map<String, Map<String, Integer>> sRFullMap =
         new HashMap<String, Map<String,Integer>>();
     
-    private final static Map<Object, Map<String, Bitmap>> sProjectBitmapCache =
-        new HashMap<Object, Map<String, Bitmap>>();
-    private final static Map<Object, Map<String, NinePatch>> sProject9PatchCache =
-        new HashMap<Object, Map<String, NinePatch>>();
+    private final static Map<Object, Map<String, SoftReference<Bitmap>>> sProjectBitmapCache =
+        new HashMap<Object, Map<String, SoftReference<Bitmap>>>();
+    private final static Map<Object, Map<String, SoftReference<NinePatch>>> sProject9PatchCache =
+        new HashMap<Object, Map<String, SoftReference<NinePatch>>>();
 
-    private final static Map<String, Bitmap> sFrameworkBitmapCache = new HashMap<String, Bitmap>();
-    private final static Map<String, NinePatch> sFramework9PatchCache =
-        new HashMap<String, NinePatch>();
+    private final static Map<String, SoftReference<Bitmap>> sFrameworkBitmapCache =
+        new HashMap<String, SoftReference<Bitmap>>();
+    private final static Map<String, SoftReference<NinePatch>> sFramework9PatchCache =
+        new HashMap<String, SoftReference<NinePatch>>();
     
     private static Map<String, Map<String, Integer>> sEnumValueMap;
 
@@ -717,15 +719,21 @@
      */
     static Bitmap getCachedBitmap(String value, Object projectKey) {
         if (projectKey != null) {
-            Map<String, Bitmap> map = sProjectBitmapCache.get(projectKey);
+            Map<String, SoftReference<Bitmap>> map = sProjectBitmapCache.get(projectKey);
             if (map != null) {
-                return map.get(value);
+                SoftReference<Bitmap> ref = map.get(value);
+                if (ref != null) {
+                    return ref.get();
+                }
             }
-            
-            return null;
+        } else {
+            SoftReference<Bitmap> ref = sFrameworkBitmapCache.get(value);
+            if (ref != null) {
+                return ref.get();
+            }
         }
-        
-        return sFrameworkBitmapCache.get(value);
+
+        return null;
     }
 
     /**
@@ -736,17 +744,17 @@
      */
     static void setCachedBitmap(String value, Bitmap bmp, Object projectKey) {
         if (projectKey != null) {
-            Map<String, Bitmap> map = sProjectBitmapCache.get(projectKey);
+            Map<String, SoftReference<Bitmap>> map = sProjectBitmapCache.get(projectKey);
 
             if (map == null) {
-                map = new HashMap<String, Bitmap>();
+                map = new HashMap<String, SoftReference<Bitmap>>();
                 sProjectBitmapCache.put(projectKey, map);
             }
             
-            map.put(value, bmp);
+            map.put(value, new SoftReference<Bitmap>(bmp));
+        } else {
+            sFrameworkBitmapCache.put(value, new SoftReference<Bitmap>(bmp));
         }
-        
-        sFrameworkBitmapCache.put(value, bmp);
     }
 
     /**
@@ -758,16 +766,22 @@
      */
     static NinePatch getCached9Patch(String value, Object projectKey) {
         if (projectKey != null) {
-            Map<String, NinePatch> map = sProject9PatchCache.get(projectKey);
+            Map<String, SoftReference<NinePatch>> map = sProject9PatchCache.get(projectKey);
             
             if (map != null) {
-                return map.get(value);
+                SoftReference<NinePatch> ref = map.get(value);
+                if (ref != null) {
+                    return ref.get();
+                }
             }
-            
-            return null;
+        } else {
+            SoftReference<NinePatch> ref = sFramework9PatchCache.get(value);
+            if (ref != null) {
+                return ref.get();
+            }
         }
         
-        return sFramework9PatchCache.get(value);
+        return null;
     }
 
     /**
@@ -778,19 +792,19 @@
      */
     static void setCached9Patch(String value, NinePatch ninePatch, Object projectKey) {
         if (projectKey != null) {
-            Map<String, NinePatch> map = sProject9PatchCache.get(projectKey);
+            Map<String, SoftReference<NinePatch>> map = sProject9PatchCache.get(projectKey);
 
             if (map == null) {
-                map = new HashMap<String, NinePatch>();
+                map = new HashMap<String, SoftReference<NinePatch>>();
                 sProject9PatchCache.put(projectKey, map);
             }
             
-            map.put(value, ninePatch);
+            map.put(value, new SoftReference<NinePatch>(ninePatch));
+        } else {
+            sFramework9PatchCache.put(value, new SoftReference<NinePatch>(ninePatch));
         }
-        
-        sFramework9PatchCache.put(value, ninePatch);
     }
-    
+
     /**
      * Implementation of {@link IWindowSession} so that mSession is not null in
      * the {@link SurfaceView}.