title: Why does my listener get deleted when I saveobj()?
body: <p>Suppose I have two classes, <code>a &lt; matlab.mixin.Copyable</code> and <code>b &lt; handle</code>.</p>
  
  <p>Here's <code>a</code>:</p>
  
  <pre><code>classdef a &lt; matlab.mixin.Copyable
      properties
          hListener
      end
  
      methods
          function obj = a(b)
              obj.newListener(b);
          end
  
          function newListener(obj, b)
              obj.hListener = addlistener(b, 'bEvent', @(o,e) disp('Received bEvent'));
          end
  
          function sobj = saveobj(obj)
              sobj = copy(obj);
  
              delete(sobj.hListener);
              sobj.hListener = [];
          end
  
      end
  end
  </code></pre>
  
  <p>and <code>b</code>:</p>
  
  <pre><code>classdef b &lt; handle
      events
          bEvent
      end
  
      methods
          function obj = b
  
          end
  
          function raiseEvent(obj)
              notify(obj, 'bEvent');
          end
      end
  
  end
  </code></pre>
  
  <p>I use <code>saveobj</code> in <code>a</code> to delete the listener upon save. I will manually re-instantiate a listener when I load the classes later.</p>
  
  <p><code>a</code> inherits from <code>matlab.mixin.Copyable</code> so I can do a <code>copy</code> during the <code>saveobj</code> operation - this way I can make a copy of the original object and change it, without affecting the original, and then save that to a MAT-file. (Supposedly - this is where my question is going.)</p>
  
  <hr>
  
  <p>Now I run the following at the command line:</p>
  
  <pre><code>&gt;&gt; bob = b; alice = a(bob);
  &gt;&gt; bob.raiseEvent
  Received bEvent
  </code></pre>
  
  <p>Everything works. Now, let's save:</p>
  
  <pre><code>&gt;&gt; save ab alice bob
  </code></pre>
  
  <p>and try to raise the event again:</p>
  
  <pre><code>&gt;&gt; bob.raiseEvent
  % NOTHING HAPPENS!
  </code></pre>
  
  <p>Turns out the listener is gone!</p>
  
  <pre><code>&gt;&gt; alice.hListener
  handle to deleted listener
  </code></pre>
  
  <p>What is going on here? Why is the <code>listener</code> object shared between <code>sobj</code> and <code>obj</code> in the <code>saveobj</code> method?</p>