diff --git a/graphics/java/android/renderscript/AllocationAdapter.java b/graphics/java/android/renderscript/AllocationAdapter.java index a6645bb591dc7..84a9ad3b1e925 100644 --- a/graphics/java/android/renderscript/AllocationAdapter.java +++ b/graphics/java/android/renderscript/AllocationAdapter.java @@ -224,7 +224,6 @@ public class AllocationAdapter extends Allocation { } static public AllocationAdapter create2D(RenderScript rs, Allocation a) { - android.util.Log.e("rs", "create2d " + a); rs.validate(); AllocationAdapter aa = new AllocationAdapter(0, rs, a); aa.mConstrainedLOD = true; diff --git a/graphics/java/android/renderscript/BaseObj.java b/graphics/java/android/renderscript/BaseObj.java index e17d79a24161a..972394358779a 100644 --- a/graphics/java/android/renderscript/BaseObj.java +++ b/graphics/java/android/renderscript/BaseObj.java @@ -109,9 +109,21 @@ public class BaseObj { return mName; } - protected void finalize() throws Throwable { - if (!mDestroyed) { - if(mID != 0 && mRS.isAlive()) { + private void helpDestroy() { + boolean shouldDestroy = false; + synchronized(this) { + if (!mDestroyed) { + shouldDestroy = true; + mDestroyed = true; + } + } + + if (shouldDestroy) { + // must include nObjDestroy in the critical section + ReentrantReadWriteLock.ReadLock rlock = mRS.mRWLock.readLock(); + rlock.lock(); + // AllocationAdapters are BaseObjs with an ID of 0 but should not be passed to nObjDestroy + if(mRS.isAlive() && mID != 0) { mRS.nObjDestroy(mID); } mRS = null;