title: Forcing an object that subscribed to events to be destroyed
body: <p>let's look at the following code:</p>
  <pre><code>type EventSource () =
  
      let myEvent = Event&lt;DateTime&gt;()
  
      do
          let timer = new Timers.Timer()
          timer.Elapsed.Add (fun _ -&gt; myEvent.Trigger DateTime.UtcNow)
          timer.Interval &lt;- TimeSpan.FromSeconds(1.).TotalMilliseconds
          timer.Enabled &lt;- true
          timer.Start()
  
      member this.OnEvent() =
          myEvent.Publish
  
  
  type DoStuff (eventSource: EventSource) =
  
      // sometimes this object will self terminate its activity
      do
          eventSource.OnEvent().Add(fun t -&gt; printfn &quot;I got the time: %A&quot; t)
  
  
  
  
  type DoStuffController () =
  
      let mutable activeObject : DoStuff option = None
  
      let eventSource = EventSource()
  
      member this.Start () =
          activeObject &lt;- Some (DoStuff(eventSource))
  
  
      member this.Stop () =
          -&gt; destroy active object here
          activeObject &lt;- None
  </code></pre>
  <p>This is a simplified version of a problem I have:
  There is a module that generates events.
  Then there is a controller that will create objects on demand (one available at a time) and these objects will subscribe to the events.
  These objects (DoStuff) can self destruct, or can be destructed on demand.</p>
  <p>Since the object has subscribed to an event, it will not go out of scope if I remove any reference to the object.</p>
  <p>What would be a good way to force the destruction?
  since the object can decide to finish its activity on its own, I was thinking to add a method that triggers the self destruction, so it is done from a single point.
  Is there any elegant way to do this?</p>
  <p>It is used in a context where an external command comes to start / stop a process; there can be only one at a time (they're different, just using the same base abstract class).
  Part of the operation requires to subscribe to events.</p>