Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android / Blur Transformation: Fix leaked RenderScript objects #1562

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

projectgoav
Copy link

@projectgoav projectgoav commented Apr 8, 2022

✨ What kind of change does this PR introduce? (Bug fix, feature, docs update...)

Manually invoke Destroy() on allocated RenderScript objects within the (Android) BlurTransformation class. Previously the assumption was that .NET Dispose() would call this for us, but this does not seem to be the case.

By not doing this, the Android runtime complains about leaked resources.

[StrictMode] StrictMode policy violation: android.os.strictmode.LeakedClosableViolation: A resource was acquired at attached stack trace but never released. See java.io.Closeable for information on avoiding resource leaks.
[StrictMode]    at android.os.StrictMode$AndroidCloseGuardReporter.report(StrictMode.java:1987)
[StrictMode]    at dalvik.system.CloseGuard.warnIfOpen(CloseGuard.java:345)
[StrictMode]    at android.renderscript.BaseObj.finalize(BaseObj.java:149)
[StrictMode]    at java.lang.Daemons$FinalizerDaemon.doFinalize(Daemons.java:291)
[StrictMode]    at java.lang.Daemons$FinalizerDaemon.runInternal(Daemons.java:278)
[StrictMode]    at java.lang.Daemons$Daemon.run(Daemons.java:139)
[StrictMode]    at java.lang.Thread.run(Thread.java:920)
[StrictMode] Caused by: java.lang.Throwable: Explicit termination method 'destroy' not called
[StrictMode]    at dalvik.system.CloseGuard.openWithCallSite(CloseGuard.java:295)
[StrictMode]    at dalvik.system.CloseGuard.open(CloseGuard.java:263)
[StrictMode]    at android.renderscript.Script.< init > (Script.java:349)
[StrictMode]    at android.renderscript.ScriptIntrinsic.< init > (ScriptIntrinsic.java:34)
[StrictMode]    at android.renderscript.ScriptIntrinsicBlur.< init > (ScriptIntrinsicBlur.java:33)
[StrictMode]    at android.renderscript.ScriptIntrinsicBlur.create(ScriptIntrinsicBlur.java:53)
[StrictMode] StrictMode policy violation: android.os.strictmode.LeakedClosableViolation: A resource was acquired at attached stack trace but never released. See java.io.Closeable for information on avoiding resource leaks.
[StrictMode]    at android.os.StrictMode$AndroidCloseGuardReporter.report(StrictMode.java:1987)
[StrictMode]    at dalvik.system.CloseGuard.warnIfOpen(CloseGuard.java:345)
[StrictMode]    at android.renderscript.BaseObj.finalize(BaseObj.java:149)
[StrictMode]    at android.renderscript.Allocation.finalize(Allocation.java:436)
[StrictMode]    at java.lang.Daemons$FinalizerDaemon.doFinalize(Daemons.java:291)
[StrictMode]    at java.lang.Daemons$FinalizerDaemon.runInternal(Daemons.java:278)
[StrictMode]    at java.lang.Daemons$Daemon.run(Daemons.java:139)
[StrictMode]    at java.lang.Thread.run(Thread.java:920)
[StrictMode] Caused by: java.lang.Throwable: Explicit termination method 'destroy' not called
[StrictMode]    at dalvik.system.CloseGuard.openWithCallSite(CloseGuard.java:295)
[StrictMode]    at dalvik.system.CloseGuard.open(CloseGuard.java:263)
[StrictMode]    at android.renderscript.Allocation.< init > (Allocation.java:425)
[StrictMode]    at android.renderscript.Allocation.< init > (Allocation.java:429)
[StrictMode]    at android.renderscript.Allocation.createFromBitmap(Allocation.java:2837)

Note: Also removed a duplicated copy of the Blur code that was commented out. Happy to revert this change if required.

⤵️ What is the current behavior?

🆕 What is the new behavior (if this is a feature change)?

💥 Does this PR introduce a breaking change?

🐛 Recommendations for testing

'StrictMode' was enabled by inserting the following to activity OnCreate

            StrictMode.SetVmPolicy(new StrictMode.VmPolicy.Builder(StrictMode.GetVmPolicy())
                                                          .DetectLeakedClosableObjects()
                                                          .Build());

📝 Links to relevant issues/docs

🤔 Checklist before submitting

  • All projects build
  • Follows style guide lines
  • Relevant documentation was updated
  • Rebased onto current develop

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant