I have a RecyclerView. The row in the recyclerview contains an ImageView. I'm using Glide to load the images (size is 30-80 KB / image). If I scrolling from top to the bottom I get OutOfMemoryException in the end. The test device is quite old: Samsung Galaxy S3.
I know there is plenty of similar questions. I've tried them all, but I haven't been successful so far.
The RecyclerView
is in a fragment in a ViewPager
(with 2 pages).
Row's layout:
...
<ImageView
android:id="@+id/catch_pic"
android:layout_width="0dp"
android:layout_height="@dimen/_250sdp"
android:layout_marginTop="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/description"/>
...
My adapter:
...
@Override
public void onBindViewHolder(@NonNull final RecyclerView.ViewHolder holder, int position) {
final Catch actualCatch = mItems.get(position);
CatchViewHolder catchHolder = (CatchViewHolder) holder;
if (actualCatch.getCatchPic() != null && !actualCatch.getCatchPic().isEmpty()) {
catchHolder.mCatchPic.setVisibility(View.VISIBLE);
Glide
.with(catchHolder.itemView.getContext())
.load(BASE_URL_FOR_IMAGES.concat(actualCatch.getCatchPic()))
.apply(new RequestOptions().transforms(new CenterCrop(), new RoundedCorners(30)).skipMemoryCache(true))
.into(catchHolder.mCatchPic);
} else {
catchHolder.mCatchPic.setVisibility(View.GONE);
}
}
@Override
public void onViewRecycled(@NonNull RecyclerView.ViewHolder holder) {
super.onViewRecycled(holder);
CatchViewHolder catchHolder = (CatchViewHolder) holder;
Glide.with(holder.itemView.getContext()).clear(catchHolder.mCatchPic);
}
...
Logcat detail(while scrolling):
I/dalvikvm-heap: Grow heap (frag case) to 14.435MB for 3768016-byte allocation
I/dalvikvm-heap: Grow heap (frag case) to 19.355MB for 1377016-byte allocation
I/dalvikvm-heap: Grow heap (frag case) to 25.652MB for 1632016-byte allocation
I/dalvikvm-heap: Grow heap (frag case) to 38.937MB for 2764816-byte allocation
I/dalvikvm-heap: Grow heap (frag case) to 42.324MB for 2160016-byte allocation
I/dalvikvm-heap: Grow heap (frag case) to 45.533MB for 2186256-byte allocation
I/dalvikvm-heap: Grow heap (frag case) to 42.929MB for 2186256-byte allocation
I/dalvikvm-heap: Grow heap (frag case) to 45.331MB for 1997584-byte allocation
I slowly go mad. Can anybody help me where is the error?
Edit #1:
If I temporarily limit the ViewPager to 1 fragment, the result is the same:
02-07 20:07:27.564 25465-25890/net.demo I/dalvikvm-heap: Grow heap (frag case) to 39.165MB for 7990288-byte allocation
02-07 20:07:28.344 25465-25892/net.demo I/dalvikvm-heap: Grow heap (frag case) to 26.725MB for 1228816-byte allocation
02-07 20:07:28.799 25465-25892/net.demo I/dalvikvm-heap: Grow heap (frag case) to 34.354MB for 7990288-byte allocation
02-07 20:07:28.869 25465-25890/net.demo I/dalvikvm-heap: Grow heap (frag case) to 41.971MB for 7990288-byte allocation
02-07 20:07:28.949 25465-25893/net.demo I/dalvikvm-heap: Grow heap (frag case) to 50.640MB for 7990288-byte allocation
02-07 20:07:29.289 25465-25892/net.demo I/dalvikvm-heap: Grow heap (frag case) to 44.330MB for 7990288-byte allocation
02-07 20:07:29.514 25465-25894/net.demo I/dalvikvm-heap: Grow heap (frag case) to 30.028MB for 3048208-byte allocation
02-07 20:07:29.884 25465-25894/net.demo I/dalvikvm-heap: Grow heap (frag case) to 32.937MB for 3048208-byte allocation
02-07 20:07:30.044 25465-25893/net.demo I/dalvikvm-heap: Grow heap (frag case) to 32.940MB for 3048208-byte allocation