title: Does an ExecutorService get garbage collected when out of scope?
body: <p>I'm asking this question because I am creating a lot of executor services and while I may already have a memory leak somewhere that needs to be investigated, I think a recent change to the following code actually worsened it, hence I am trying to confirm what is going on:</p>
  
  <pre><code>@FunctionalInterface
  public interface BaseConsumer extends Consumer&lt;Path&gt; {
      @Override
      default void accept(final Path path) {
          String name = path.getFileName().toString();
          ExecutorService service = Executors.newSingleThreadExecutor(runnable -&gt; {
              Thread thread = new Thread(runnable, "documentId=" + name);
              thread.setDaemon(true);
              return thread;
          });
          Future&lt;?&gt; future = service.submit(() -&gt; {
              baseAccept(path);
              return null;
          });
          try {
              future.get();
          } catch (InterruptedException ex) {
              Thread.currentThread().interrupt();
          } catch (ExecutionException ex) {
              throw new RuntimeException(ex);
          }
      }
  
      void baseAccept(final Path path) throws Exception;
  }
  </code></pre>
  
  <p>Then this <code>Consumer&lt;Path&gt;</code> gets called on another thread pool with (usually) N=2 threads, I am not sure if that is relevant.</p>
  
  <p>The question is: Does the <code>ExecutorService service</code> go out of scope <em>and</em> get garbage collected once <code>BaseConsumer#accept</code> has finished?</p>