Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1b4df169 authored by Yang Ni's avatar Yang Ni
Browse files

Fixed BaseObj finalizer and destroy()

Bug: 28242626
Bug: 27972184
Bug: 27973681

This is resolving issues in ScriptGroup (V1) again.
In ScriptGroup.destroy(), we also need to consider the old API where
mClosures is not initialized.

Also cleaned up the finalizer for ScriptGroup and Allocation:
Since BaseObj.finalize() calls BaseObj.helpDestroy(), instead of
BaseObj.destroy(), there is no possibility that the finalizers of
child objects may race their parents finalizers. Note that
helpDestroy() does not try to recurse on child objects.

Change-Id: I9dbb2b60f8478f656f8a418c2b5fc8d6848aeef0
parent 54d056ed
Loading
Loading
Loading
Loading
+0 −3
Original line number Diff line number Diff line
@@ -392,8 +392,6 @@ public class Allocation extends BaseObj {

    protected void finalize() throws Throwable {
        RenderScript.registerNativeFree.invoke(RenderScript.sRuntime, mSize);
        // Set mType null to avoid double-destroying it in case its finalizer races ahead
        mType = null;
        super.finalize();
    }

@@ -2615,7 +2613,6 @@ public class Allocation extends BaseObj {

        if (mType != null && mOwningType) {
            mType.destroy();
            mType = null;
        }

        super.destroy();
+5 −12
Original line number Diff line number Diff line
@@ -1066,19 +1066,12 @@ public final class ScriptGroup extends BaseObj {
     */
    public void destroy() {
        super.destroy();
        // ScriptGroup created using the old Builder class does not
        // initialize the field mClosures
        if (mClosures != null) {
            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.
        if (mClosures != null) {
            // ScriptGroup created using the old Builder class does not
            // initialize the field mClosures
            mClosures.clear();
        }
        super.finalize();
    }
}