Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Typed Array should be recycled after use with #recycle()

My code is showing this warning message:

Typed Array should be recycled after use with #recycle() for obtainedTypedArray

Code:

public View getView(int i, View view, ViewGroup viewgroup)
{
    ImageView imageview;
    if (view == null)
    {
        imageview = new ImageView(b);
        imageview.setLayoutParams(new android.widget.AbsListView.LayoutParams(110, 110));
        imageview.setPadding(1, 1, 1, 1);
        imageview.setAdjustViewBounds(false);
        imageview.setScaleType(android.widget.ImageView.ScaleType.CENTER_CROP);
    } else
    {
        imageview = (ImageView)view;
    }
    imageview.setImageResource(a.getResources().obtainTypedArray(0x7f050000).getResourceId(i, -1)); //*warning*Typed Array should be recycled after use with #recycle()
    return imageview;
}
like image 918
Mojo Jojo Avatar asked Jan 25 '14 18:01

Mojo Jojo


People also ask

What is a typed array in Java?

Array in java is a group of like-typed variables referred to by a common name. Arrays in Java work differently than they do in C/C++.

What is TypedArray recycle?

recycle basically means..free/clearing all the data associated with corresponding resource. In Android we can find recycle for Bitmap and TypedArray. If you check both source files then you can find a boolean variable "mRecycled" which is "false"(default value). It is assigned to "true" when recycle is called.

What is typed array Kotlin?

toTypedArray(): Array<T> Returns a typed array containing all of the elements of this collection. Allocates an array of runtime type T having its size equal to the size of this collection and populates the array with the elements of this collection.

What is TypedArray?

The JavaScript TypedArray object illustrates an array like view of an underlying binary data buffer. There are many number of different global properties, whose values are TypedArray constructors for specific element types, listed below.


1 Answers

You should hold onto the TypedArray you get back from obtainTypedArray() and call recycle() on it after using it.

Also, hard-coding a hex value like 0x7f050000 is unlikely to be the right answer.

like image 150
CommonsWare Avatar answered Sep 17 '22 13:09

CommonsWare