Giter Site home page Giter Site logo

Comments (4)

cchcc avatar cchcc commented on August 28, 2024

뷰모델 소스를 보시면 아래와 같이 레퍼런스를 null 로 초기화시켜주고 있고onCleared 메소드는 액티비티의 onDestory 시점에 호출되어 메모리릭이 발생하지 않습니다. (FragmentActivity 소스를 보시면 됩니다)

override fun onCleared() {
        coordinator = null  // avoid memory leak
}

언급하시것중에 '강한결합'이라는 말은 객체가 의존성의 구현객체를 직접적으로 들고 있을때 사용하는 표현이 아닌가 싶네요. 이를 테면

class Com(val view: View)

class Host(val com: Com)  // 강결합

이를 약한결합으로 만들어 보자면

interface Com
class ComImpl(val view: View) : Com

class Host(val com: Com) // 약결합

위의 약결합 예를 보면 Host 입장에서는 com 이 view 를 들고있는지 없는지 알수가 없죠.

from android-mvvm-unittest.

cchcc avatar cchcc commented on August 28, 2024

@iam1492 다시 소스를 보고 곰곰히 생각해보니 아래경우에 메모리릭 & 버그가 발생할수 있겠네요.

  1. 최초 액티비티, 뷰모델 생성
  2. 사용자가 설정에서 언어변경함
  3. 액티비티 onDestory 호출
  4. onDestory 시점에서 설정변경이라 뷰모델의 onCleared 호출안됨
  5. navigator 의 activity 는 기존꺼 유지

의견 감사합니다. 좀더 고민해서 소스를 수정해보겠습니다.

from android-mvvm-unittest.

cchcc avatar cchcc commented on August 28, 2024

7804e50
액티비티의 onDestory 시점에 navigator.activity 를 null 로 초기화하도록 수정했습니다.

from android-mvvm-unittest.

iam1492 avatar iam1492 commented on August 28, 2024

@cchcc 제가 깊이 있게 생각했던건 아니였는데 그래도 릭이 생길 수 있는 부분을 찾으셔서 다행이네요~ 자세한 설명도 감사합니다 👍

from android-mvvm-unittest.

Related Issues (1)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.