@DsfServiceEventHandler
  public void eventDispatched(IExitedDMEvent event) {
    // If a memory context is exiting, save expressions and clean its used resources
    if (event.getDMContext() instanceof IMemoryDMContext) {
      IMemoryDMContext memDmc = (IMemoryDMContext) event.getDMContext();
      // Remove entry if it exists
      final IMemoryBlockRetrieval retrieval = fMapMemDMCToBlockRetrieval.remove(memDmc);
      if (retrieval != null) {
        if (retrieval instanceof DsfMemoryBlockRetrieval) {
          ((DsfMemoryBlockRetrieval) retrieval).saveMemoryBlocks();
        }
        // Fire a terminate event for the memory retrieval object so
        // that the hosting memory views can clean up. See 255120 and
        // 283586
        DebugPlugin.getDefault()
            .fireDebugEventSet(new DebugEvent[] {new DebugEvent(retrieval, DebugEvent.TERMINATE)});

        Job removeJob = new Job("Removing memory blocks") { // $NON-NLS-1$

              @Override
              protected IStatus run(IProgressMonitor monitor) {
                IMemoryBlockManager mbm = DebugPlugin.getDefault().getMemoryBlockManager();
                IMemoryBlock[] deletedMemoryBlocks = mbm.getMemoryBlocks(retrieval);
                mbm.removeMemoryBlocks(deletedMemoryBlocks);
                return Status.OK_STATUS;
              }
            };
        removeJob.schedule();
      }
    }
  }
  @DsfServiceEventHandler
  public void eventDispatched(IStartedDMEvent event) {
    // If a new memory context is starting, create its memory retrieval instance
    if (event.getDMContext() instanceof IMemoryDMContext) {
      IMemoryDMContext memDmc = (IMemoryDMContext) event.getDMContext();
      if (!fMapMemDMCToBlockRetrieval.containsKey(memDmc)) {
        // We need a new memory retrieval for this new memory context
        IMemoryBlockRetrieval memRetrieval = null;
        try {
          memRetrieval = createMemoryBlockRetrieval(fModelId, fLaunchConfig, fSession);
        } catch (DebugException e) {
          DsfPlugin.getDefault().getLog().log(e.getStatus());
          return;
        }

        if (memRetrieval != null) {
          if (memRetrieval instanceof DsfMemoryBlockRetrieval) {
            ((DsfMemoryBlockRetrieval) memRetrieval).initialize(memDmc);
          }

          fMapMemDMCToBlockRetrieval.put(memDmc, memRetrieval);
        }
      }
    }
  }