2

I've been having problems with memory management while using RenderScript, so I figured that since Allocation.createFromBitmap()/createTyped() consumes memory, Allocation.destroy() frees the memory consumed by it.

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

Gensoukyou1337
  • 1,507
  • 1
  • 13
  • 31

1 Answers1

2

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.

Miao Wang
  • 1,120
  • 9
  • 12