summaryrefslogtreecommitdiffstats
path: root/tools/layoutlib/bridge/src/android/graphics/DashPathEffect_Delegate.java
diff options
context:
space:
mode:
authorXavier Ducrohet <xav@android.com>2011-02-22 11:54:37 -0800
committerXavier Ducrohet <xav@android.com>2011-02-23 12:00:41 -0800
commitcc4977d0fdaf657907912fd6cc2f9426dc8d2e36 (patch)
treea49b4d71fa36d705dd6659f872bb8339fc357825 /tools/layoutlib/bridge/src/android/graphics/DashPathEffect_Delegate.java
parent8cb6fc184dcb9cc6ab0871de5cf430277d15c8c8 (diff)
downloadframeworks_base-cc4977d0fdaf657907912fd6cc2f9426dc8d2e36.zip
frameworks_base-cc4977d0fdaf657907912fd6cc2f9426dc8d2e36.tar.gz
frameworks_base-cc4977d0fdaf657907912fd6cc2f9426dc8d2e36.tar.bz2
LayoutLib: Hold onto delegate references.
When an object is given a delegate to hold onto, keep the reference to the delegate instead of its native integer. Also change the way the finalizer works by not explicitely deleting the delegate. Instead we want the delegate to be deleted when nothing holds a reference to it. To do this, instead of using a regular SparseArray, we use a SparseArray of WeakReferences. Because the main Java object that "owns" the delegate does not actually holds a reference to the delegate, we fake this by having the delegate manager hold a reference to delegates for the main object. This is added/removed as the object is created and the native finalized is called. This makes layoutlib behave more like the JNI code where the native objects are reference counted, and where the Java object can be deleted but the delegate it owns is kept around (usually because another type of delegates hold a reference on it.) To properly handle the WeakReferences, we need to be able to regularly clear the SparseArray of WeakReference that were referencing objects that have been GC'ed. Since the SparseArray is regularly being compacted (actually only when items are removed), we use a custom SparseWeakArray (started as a straight copy of SparseArray) that handles the WeakReference and takes care of compacting the array by removing deleted indices and WeakReference that returns null. Since our specific use case doesn't call actually delete() or remove(), the compacting only happens when the array needs to be resized. Change-Id: Iacc5c1ff5b21732b8816fda87eb090da12d034e0
Diffstat (limited to 'tools/layoutlib/bridge/src/android/graphics/DashPathEffect_Delegate.java')
-rw-r--r--tools/layoutlib/bridge/src/android/graphics/DashPathEffect_Delegate.java2
1 files changed, 1 insertions, 1 deletions
diff --git a/tools/layoutlib/bridge/src/android/graphics/DashPathEffect_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/DashPathEffect_Delegate.java
index 12a4d4a..d97c2ec 100644
--- a/tools/layoutlib/bridge/src/android/graphics/DashPathEffect_Delegate.java
+++ b/tools/layoutlib/bridge/src/android/graphics/DashPathEffect_Delegate.java
@@ -75,7 +75,7 @@ public final class DashPathEffect_Delegate extends PathEffect_Delegate {
@LayoutlibDelegate
/*package*/ static int nativeCreate(float intervals[], float phase) {
DashPathEffect_Delegate newDelegate = new DashPathEffect_Delegate(intervals, phase);
- return sManager.addDelegate(newDelegate);
+ return sManager.addNewDelegate(newDelegate);
}
// ---- Private delegate/helper methods ----