Gensoukyou1337 Gensoukyou1337 - 1 year ago 49
Android Question

RenderScript - is it good practice to call Allocation.destroy() on every Allocation object created when you're done with it?

I've been having problems with memory management while using RenderScript, so I figured that since

consumes memory,
frees the memory consumed by it.

Is it good practice to do so, and what else is good practice for RenderScript-based programs?

Answer Source

The finalizer of Allocation will reclaim the memories when GC happens.

However, yes, it is a good practice to destroy Allocations when you don't need them any more.

One comment: it is usually a good practice to call Allocation.createFromBitmap(RenderScript rs, Bitmap b) when creating Allocations from a bitmap. It would make the Allocation share the data with the bitmap, thus you don't need to copy back and forth, as long as the stride of the bitmap is aligned on a 32bytes or 16bytes boundary.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download