PlaceHolderView
PlaceHolderView copied to clipboard
Memory leak on card swipe
Hey, i'm having problems with memory leaks in my app. On my cardView (like tinder) i'm using glide to load pictures and i'm setting up some view parameters, i'm also using private method to play some animations, in this method i'm passing view reference (the one annotated by @View) in arguments. In this method there is LayoutInflater from which i take view reference. Code looks similar to the one i post below, i think this tvMark and mBlAnswer are leaking when i swipe a card, do you have any idea what should i do to prevent this?
@NonReusable
@Layout(R.layout.item_either_question_card)
public class EitherQuestionCard {
@View(R.id.item_question_card_ivAnswer)
private ImageView mIvAnswer;
@View(R.id.item_question_card_blAnswer)
private BlurLayout mBlAnswer;
@Resolve
private void onResolved() {
Glide.with(mContext).load(mQuestion.getAnswerPicture())
.apply(RequestOptions.fitCenterTransform()).into(mIvAnswer);
revealAnswer(mBlAnswer)
}
private void revealAnswer(BlurLayout blurLayout) {
android.view.View hover = LayoutInflater.from(mContext).inflate(R.layout.hover_answer_summary, null);
TextView tvMark = hover.findViewById(R.id.hover_answer_summary_tvMark);
tvMark.setText("ok");
blurLayout.setHoverView(hover);
blurLayout.showHover();
}
}
@Tokimu When you use @NonReusable
then on the card swipe the GC can collect it. If you have passed the reference to this View in some other class then make sure when @SwipeIn
or @SwipeOut
is called you set those references to null
Why are you using LayoutInflater?
@janishar Thanks for your answer. Okay so it's good i'm using @NonReusable, i think this view i get from LayoutInflater is not collected by GC. I need LayoutInflater to get the reference of the View from different Layout file than my card is using, i couldn't manage to get it using @Layout or @View annotations.
Do you know any other way to get reference to the view from other layout than the one annotated by @Layout and without using LayoutInflater?