title: Do lambda expressions hold a reference to their enclosing instance when accessing a class member that is a reference?
body: <p>I think the easiest way to describe my question is with an example:</p>
  
  <pre><code>class Enclosing {
      private ObjectOfInterest o = new ObjectOfInterest();
      public void registerEventListener() {
          EventEmitter.onEvent(() -&gt; {
              // Need to access 'o' here, while 'this' is not important.
              o.yeeha();
          });
      }
  }
  </code></pre>
  
  <p>Does the lambda expression hold an implicit reference to its <code>Enclosing</code> instance? If so, how can I avoid this to avoid memory leaks? I need to access <code>o</code> in the event listener, but not the enclosing instance.</p>
  
  <p>BTW, I found the question "<a href="https://stackoverflow.com/questions/28446626/does-java8-lambdas-maintains-a-reference-to-their-enclosing-instance-like-anonym">Does Java8 lambdas maintains a reference to their enclosing instance like anonymous classes?</a>", but it is not clear to me when exactly the lambda expression is considered to "not capture members from the enclosing instance". In addition, <a href="http://cr.openjdk.java.net/~briangoetz/lambda/lambda-state-4.html" rel="nofollow noreferrer">the document that is referenced in the accepted answer</a> declares itself as outdated.</p>