title: What happens if SparkSession is not closed?
body: <p>What's the difference between the following 2?</p>
  
  <pre><code>object Example1 {
      def main(args: Array[String]): Unit = {
          try {
              val spark = SparkSession.builder.getOrCreate
              // spark code here
          } finally {
              spark.close
          }
      }
  }
  
  object Example2 {
      val spark = SparkSession.builder.getOrCreate
      def main(args: Array[String]): Unit = {
          // spark code here
      }
  }    
  </code></pre>
  
  <p>I know that SparkSession implements Closeable and it hints that it needs to be closed. However, I can't think of any issues if the SparkSession is just created as in Example2 and never closed directly.</p>
  
  <p>In case of success or failure of the Spark application (and exit from main method), the JVM will terminate and the SparkSession will be gone with it. Is this correct?</p>
  
  <p>IMO: The fact that the SparkSession is a singleton should not make a big difference either.</p>