diff options
author | Yang Ni <yangni@google.com> | 2016-04-12 16:00:46 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2016-04-12 16:00:47 +0000 |
commit | 01db88335d8cb80eaa9698321bb9e7e5e974f195 (patch) | |
tree | 826bd31136f864527c7894a2529270be6a1596a7 | |
parent | e8f7b80bcd1e7b73c82e3abf3f2fa50faed93ee1 (diff) | |
parent | 44e2f45f0cab4a429e59f07c1e5bf0eef08c7819 (diff) |
Merge "Destroy Closures in ScriptGroup"
-rw-r--r-- | rs/java/android/renderscript/ScriptGroup.java | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/rs/java/android/renderscript/ScriptGroup.java b/rs/java/android/renderscript/ScriptGroup.java index 219f16b91baf..35ae8b406e45 100644 --- a/rs/java/android/renderscript/ScriptGroup.java +++ b/rs/java/android/renderscript/ScriptGroup.java @@ -187,6 +187,23 @@ public final class ScriptGroup extends BaseObj { guard.open("destroy"); } + /** + * Destroys this Closure and the Allocation for its return value + */ + public void destroy() { + super.destroy(); + if (mReturnValue != null) { + mReturnValue.destroy(); + } + } + + protected void finalize() throws Throwable { + // Set null mReturnValue to avoid double-destroying it, in case its + // finalizer races ahead. + mReturnValue = null; + super.finalize(); + } + private void retrieveValueAndDependenceInfo(RenderScript rs, int index, Script.FieldID fid, Object obj, long[] values, int[] sizes, @@ -1015,6 +1032,8 @@ public final class ScriptGroup extends BaseObj { throw new RSIllegalArgumentException("invalid script group name"); } ScriptGroup ret = new ScriptGroup(mRS, name, mClosures, mInputs, outputs); + mClosures = new ArrayList<Closure>(); + mInputs = new ArrayList<Input>(); return ret; } @@ -1042,4 +1061,20 @@ public final class ScriptGroup extends BaseObj { } + /** + * Destroy this ScriptGroup and all Closures in it + */ + public void destroy() { + super.destroy(); + for(Closure c : mClosures) { + c.destroy(); + } + } + + protected void finalize() throws Throwable { + // Clear out the list mClosures to avoid double-destroying the closures, + // in case their finalizers race ahead. + mClosures.clear(); + super.finalize(); + } } |