private var _binding: ResultProfileBinding? = null
// This property is only valid between onCreateView and
// onDestroyView.
private val binding get() = _binding!!
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
_binding = ResultProfileBinding.inflate(inflater, container, false)
val view = binding.root
return view
}
override fun onDestroyView() {
super.onDestroyView()
_binding = null
}
https://developer.android.com/topic/libraries/view-binding#fragments
binding 변수는 nullable한 타입으로 사용한다.
onDestroyView에서 binding 인스턴스를 null로 초기화한다.
-> Fragment는 View 보다 오래 지속되므로 불필요한 메모리 누수가 생기는 것을 방지
'Android > 메모' 카테고리의 다른 글
[Android] RxJava3, Retrofit 사용 시 RxJava3CallAdapterFactory 추가 (1) | 2022.09.19 |
---|---|
[Android] 데이터바인딩 사용 시 숫자에 콤마(comma) 넣기 (0) | 2022.04.05 |
댓글