Skip to content

Commit 1fc0e75

Browse files
authored
fix: prevent OOM by de-referencing images when they are not required … (#2468)
1 parent 161683f commit 1fc0e75

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

app/src/main/java/io/pslab/fragment/PSLabPinLayoutFragment.java

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,6 @@
66
import android.graphics.Matrix;
77
import android.graphics.PointF;
88
import android.os.Bundle;
9-
10-
import androidx.annotation.NonNull;
11-
import androidx.appcompat.app.AlertDialog;
12-
import androidx.core.content.res.ResourcesCompat;
13-
import androidx.fragment.app.Fragment;
14-
159
import android.view.LayoutInflater;
1610
import android.view.MotionEvent;
1711
import android.view.View;
@@ -20,6 +14,11 @@
2014
import android.widget.ImageView;
2115
import android.widget.TextView;
2216

17+
import androidx.annotation.NonNull;
18+
import androidx.appcompat.app.AlertDialog;
19+
import androidx.core.content.res.ResourcesCompat;
20+
import androidx.fragment.app.Fragment;
21+
2322
import java.util.ArrayList;
2423

2524
import io.pslab.R;
@@ -45,6 +44,8 @@ public class PSLabPinLayoutFragment extends Fragment implements View.OnTouchList
4544

4645
private ImageView colorMap;
4746

47+
private ImageView imgLayout;
48+
4849
public static PSLabPinLayoutFragment newInstance() {
4950
return new PSLabPinLayoutFragment();
5051
}
@@ -53,16 +54,27 @@ public static PSLabPinLayoutFragment newInstance() {
5354
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
5455
Bundle savedInstanceState) {
5556
View view = inflater.inflate(R.layout.fragment_pin_layout, container, false);
56-
ImageView imgLayout = view.findViewById(R.id.img_pslab_pin_layout);
57+
imgLayout = view.findViewById(R.id.img_pslab_pin_layout);
5758
colorMap = view.findViewById(R.id.img_pslab_color_map);
59+
return view;
60+
}
61+
62+
@Override
63+
public void onResume() {
64+
super.onResume();
5865
imgLayout.setImageDrawable(ResourcesCompat.getDrawable(getResources(),
5966
frontSide ? R.drawable.pslab_v5_front_layout : R.drawable.pslab_v5_back_layout, null));
6067
colorMap.setImageDrawable(ResourcesCompat.getDrawable(getResources(),
6168
frontSide ? R.drawable.pslab_v5_front_colormap : R.drawable.pslab_v5_back_colormap, null));
6269
imgLayout.setOnTouchListener(this);
6370
populatePinDetails();
71+
}
6472

65-
return view;
73+
@Override
74+
public void onPause() {
75+
super.onPause();
76+
imgLayout.setImageDrawable(null);
77+
colorMap.setImageDrawable(null);
6678
}
6779

6880
private void populatePinDetails() {

0 commit comments

Comments
 (0)