title: Android coroutine viewmodelscope cancel
body: <p>I have seen a lot of examples that use a job as a way to cancel coroutines when viewmodel is destroyed.</p>
  
  <pre><code>class SetupViewModel : ViewModel() {
  
      private val completableJob = Job()
      private val coroutineScope = CoroutineScope(Dispatchers.IO + completableJob)
  
      override fun onCleared() {
          super.onCleared()
          completableJob.cancel()
      }
  }
  </code></pre>
  
  <p>The strange thing for me is no one seems to be using coroutineScope to do that. I think that should be easier and has less code. Any idea? </p>
  
  <pre><code>class SetupViewModel : ViewModel() {
      private val coroutineScope = CoroutineScope(Dispatchers.IO)
  
      override fun onCleared() {
          super.onCleared()
          coroutineScope.cancel()
      }
  }
  </code></pre>