Index: /trunk/src/VBox/Frontends/VBoxManage/VBoxManageMisc.cpp
===================================================================
--- /trunk/src/VBox/Frontends/VBoxManage/VBoxManageMisc.cpp	(revision 31217)
+++ /trunk/src/VBox/Frontends/VBoxManage/VBoxManageMisc.cpp	(revision 31218)
@@ -160,8 +160,27 @@
     {
         SafeArray<BSTR> abstrFiles;
-        CHECK_ERROR(machine, Unregister(false /* fDetachMedia */,
+        CHECK_ERROR(machine, Unregister(fDelete /* fAutoCleanup */,
                                         ComSafeArrayAsOutParam(abstrFiles)));
-        if (SUCCEEDED(rc) && fDelete)
-            CHECK_ERROR(machine, Delete());
+        if (SUCCEEDED(rc))
+        {
+            for (size_t u = 0;
+                 u < abstrFiles.size();
+                 ++u)
+            {
+                Utf8Str strFile(abstrFiles[u]);
+                if (fDelete)
+                {
+                    RTPrintf("Deleting '%s'\n", strFile.c_str());
+                    RTFileDelete(strFile.c_str());
+                }
+                else
+                    RTPrintf("File '%s' is now obsolete and can be deleted\n", strFile.c_str());
+            }
+
+            if (fDelete)
+            {
+                CHECK_ERROR(machine, Delete());
+            }
+        }
     }
     return SUCCEEDED(rc) ? 0 : 1;
@@ -423,5 +442,5 @@
                 ComPtr<IConsole> console;
                 CHECK_ERROR_BREAK(a->session, COMGETTER(Console)(console.asOutParam()));
-                CHECK_ERROR_BREAK(console, ForgetSavedState(true));
+                CHECK_ERROR_BREAK(console, ForgetSavedState());
             } while (0);
             CHECK_ERROR_BREAK(a->session, UnlockMachine());
Index: /trunk/src/VBox/Frontends/VBoxSDL/VBoxSDL.cpp
===================================================================
--- /trunk/src/VBox/Frontends/VBoxSDL/VBoxSDL.cpp	(revision 31217)
+++ /trunk/src/VBox/Frontends/VBoxSDL/VBoxSDL.cpp	(revision 31218)
@@ -1652,5 +1652,5 @@
         if (machineState == MachineState_Saved)
         {
-            CHECK_ERROR(gConsole, ForgetSavedState(true));
+            CHECK_ERROR(gConsole, ForgetSavedState());
         }
         /*
Index: /trunk/src/VBox/Frontends/VirtualBox/src/selector/VBoxSelectorWnd.cpp
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/selector/VBoxSelectorWnd.cpp	(revision 31217)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/selector/VBoxSelectorWnd.cpp	(revision 31218)
@@ -805,5 +805,5 @@
 
     CConsole console = session.GetConsole();
-    console.ForgetSavedState(true);
+    console.ForgetSavedState();
     if (!console.isOk())
         vboxProblem().cannotDiscardSavedState (console);
Index: /trunk/src/VBox/Main/ConsoleImpl.cpp
===================================================================
--- /trunk/src/VBox/Main/ConsoleImpl.cpp	(revision 31217)
+++ /trunk/src/VBox/Main/ConsoleImpl.cpp	(revision 31218)
@@ -2387,5 +2387,5 @@
 }
 
-STDMETHODIMP Console::ForgetSavedState(BOOL aRemove)
+STDMETHODIMP Console::ForgetSavedState()
 {
     AutoCaller autoCaller(this);
@@ -2400,7 +2400,4 @@
 
     HRESULT rc = S_OK;
-
-    rc = mControl->SetRemoveSavedState(aRemove);
-    if (FAILED(rc)) return rc;
 
     /*
Index: /trunk/src/VBox/Main/MachineImpl.cpp
===================================================================
--- /trunk/src/VBox/Main/MachineImpl.cpp	(revision 31217)
+++ /trunk/src/VBox/Main/MachineImpl.cpp	(revision 31218)
@@ -4062,5 +4062,5 @@
 
 /** @note Locks objects! */
-STDMETHODIMP Machine::Unregister(BOOL fCloseMedia,
+STDMETHODIMP Machine::Unregister(BOOL fAutoCleanup,
                                  ComSafeArrayOut(BSTR, aFiles))
 {
@@ -4076,9 +4076,21 @@
                            mUserData->mName.raw());
 
-    // @todo optionally discard saved state
+    // this list collects the files that should be reported
+    // as to be deleted to the caller in aFiles
+    std::list<Bstr> llFilesForCaller;
+
+    // discard saved state
     if (mData->mMachineState == MachineState_Saved)
-        return setError(VBOX_E_INVALID_VM_STATE,
-                        tr("Cannot unregister the machine '%ls' because it is in the Saved state"),
-                           mUserData->mName.raw());
+    {
+        // add the saved state file to the list of files the caller should delete
+        Assert(!mSSData->mStateFilePath.isEmpty());
+        llFilesForCaller.push_back(Bstr(mSSData->mStateFilePath));
+
+        mSSData->mStateFilePath.setNull();
+
+        // unconditionally set the machine state to powered off, we now
+        // know no session has locked the machine
+        mData->mMachineState = MachineState_PoweredOff;
+    }
 
     // @todo optionally nuke snapshots
@@ -4089,5 +4101,5 @@
         return setError(VBOX_E_INVALID_OBJECT_STATE,
                         tr("Cannot unregister the machine '%ls' because it has %d snapshots"),
-                           mUserData->mName.raw(), snapshotCount);
+                        mUserData->mName.raw(), snapshotCount);
 
     if (    !mMediaData.isNull()      // can be NULL if machine is inaccessible
@@ -4096,5 +4108,5 @@
     {
         // we have media attachments:
-        if (fCloseMedia)
+        if (fAutoCleanup)
         {
             // caller wants automatic detachment: then do that and report all media to the array
@@ -4122,5 +4134,5 @@
             return setError(VBOX_E_INVALID_OBJECT_STATE,
                             tr("Cannot unregister the machine '%ls' because it has %d media attachments"),
-                               mMediaData->mAttachments.size());
+                            mUserData->mName.raw(), mMediaData->mAttachments.size());
     }
 
@@ -4133,8 +4145,7 @@
     alock.release();
 
-    if (fCloseMedia)
+    if (fAutoCleanup)
     {
         // now go thru the list of attached media reported by prepareUnregister() and close them all
-        SafeArray<BSTR> sfaFiles(llMedia.size());
         size_t u = 0;
         for (MediaList::const_iterator it = llMedia.begin();
@@ -4153,12 +4164,20 @@
 
             // report the path to the caller
-            bstrFile.detachTo(&sfaFiles[u]);
+            llFilesForCaller.push_back(bstrFile);
             ++u;
         }
-        // report all paths to the caller
-        sfaFiles.detachTo(ComSafeArrayOutArg(aFiles));
-    }
+    }
+
+    // report all paths to the caller
+    SafeArray<BSTR> sfaFiles(llFilesForCaller.size());
+    size_t i = 0;
+    for (std::list<Bstr>::iterator it = llFilesForCaller.begin();
+         it != llFilesForCaller.end();
+         ++it)
+        it->detachTo(&sfaFiles[i++]);
+    sfaFiles.detachTo(ComSafeArrayOutArg(aFiles));
 
     mParent->unregisterMachine(this);
+            // calls VirtualBox::saveSettings()
 
     return S_OK;
@@ -9637,7 +9656,4 @@
     }
 
-    /* default is to delete saved state on Saved -> PoweredOff transition */
-    mRemoveSavedState = true;
-
     /* Confirm a successful initialization when it's the case */
     autoInitSpan.setSucceeded();
@@ -9933,19 +9949,4 @@
 
 /**
- *  @note Locks this object for writing.
- */
-STDMETHODIMP SessionMachine::SetRemoveSavedState(BOOL aRemove)
-{
-    AutoCaller autoCaller(this);
-    AssertComRCReturn(autoCaller.rc(), autoCaller.rc());
-
-    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
-
-    mRemoveSavedState = aRemove;
-
-    return S_OK;
-}
-
-/**
  *  @note Locks the same as #setMachineState() does.
  */
@@ -11236,9 +11237,6 @@
     if (deleteSavedState)
     {
-        if (mRemoveSavedState)
-        {
-            Assert(!mSSData->mStateFilePath.isEmpty());
-            RTFileDelete(mSSData->mStateFilePath.c_str());
-        }
+        Assert(!mSSData->mStateFilePath.isEmpty());
+        RTFileDelete(mSSData->mStateFilePath.c_str());
         mSSData->mStateFilePath.setNull();
         stsFlags |= SaveSTS_StateFilePath;
Index: /trunk/src/VBox/Main/idl/VirtualBox.xidl
===================================================================
--- /trunk/src/VBox/Main/idl/VirtualBox.xidl	(revision 31217)
+++ /trunk/src/VBox/Main/idl/VirtualBox.xidl	(revision 31218)
@@ -3192,16 +3192,8 @@
   <interface
      name="IInternalMachineControl" extends="$unknown"
-     uuid="26604a54-8628-491b-a0ea-e1392a16d13b"
+     uuid="e2da8b1a-2ad1-490e-b29e-c33a144791b6"
      internal="yes"
      wsmap="suppress"
      >
-    <method name="setRemoveSavedState">
-      <desc>
-        Updates the flag whether saved state is removed on a machine state
-        change from Saved to PoweredOff.
-      </desc>
-      <param name="aRemove" type="boolean" dir="in"/>
-    </method>
-
     <method name="updateState">
       <desc>
@@ -5190,16 +5182,29 @@
       <desc>
         Unregisters the machine, which must have been previously registered using
-        <link to="IVirtualBox::registerMachine"/>. After successful method invocation,
+        <link to="IVirtualBox::registerMachine"/>.
+
+        This method will succeed even if the machine currently has media attachments or
+        is in the <link to="MachineState::Saved">Saved</link> state. In those cases,
+        the caller receives the names of all files that have been made obsolete by the
+        call in the @a aFiles array parameter. This list will consist of the saved
+        state file and all storage files by media that were detached from the machine.
+
+        <note>
+          The @a fAutoCleanup parameter is temporary to avoid substantial changes to the
+          frontends in SVN trunk.It will go away before the 3.3 release and
+          always be true then. If fAutoCleanup is false, the API currently behaves like
+          the old VirtualBox::UnregisterMachine API. Cleaning up snapshots does not work
+          yet, so the method will still fail if the machine has snapshots.
+        </note>
+
+        The settings XML file of the machine object itself will not be included in that
+        list; call <link to="#delete" /> for that.
+
+        The call will fail if the machine is currently locked (see <link to="ISession" />).
+        It implicitly calls <link to="#saveSettings"/> to save all current machine settings
+        before unregistering it.
+
+        After successful method invocation,
         the <link to="IMachineRegisteredEvent"/> event is fired.
-
-        <note>
-          The specified machine must not be in the Saved state nor have an open
-          (or a spawning) direct session associated with it.
-        </note>
-
-        <note>
-          This method implicitly calls <link to="#saveSettings"/> to
-          save all current machine settings before unregistering it.
-        </note>
 
         <note>
@@ -5210,16 +5215,10 @@
         </note>
 
-        <result name="VBOX_E_OBJECT_NOT_FOUND">
-          Could not find registered machine matching @a id.
-        </result>
-        <result name="VBOX_E_INVALID_VM_STATE">
-          Machine is in Saved state.
-        </result>
         <result name="VBOX_E_INVALID_OBJECT_STATE">
-          Machine has snapshot or open session or medium attached.
-        </result>
-      </desc>
-
-      <param name="fCloseMedia" type="boolean" dir="in">
+          Machine has snapshot or is locked.
+        </result>
+      </desc>
+
+      <param name="fAutoCleanup" type="boolean" dir="in">
         <desc>If true, the method will automatically detach all media from the
           machine and its snapshots, call <link to="IMedium::close" /> on each
@@ -5227,5 +5226,6 @@
           the caller in the @a aFiles array so the caller can then delete the
           image files.
-          If false, the method will fail if media attachments are present.</desc>
+          If false, the method will fail if media attachments are present.
+        </desc>
       </param>
       <param name="aFiles" type="wstring" safearray="yes" dir="return">
@@ -5933,5 +5933,5 @@
   <interface
      name="IConsole" extends="$unknown"
-     uuid="9e467cff-98fc-4f5b-83aa-048d903694c9"
+     uuid="3a7bb20e-bbee-47f2-a5ee-b158555f2c79"
      wsmap="managed"
      >
@@ -6301,8 +6301,8 @@
     <method name="forgetSavedState">
       <desc>
-        Forgets the saved state of the virtual machine previously created
-        by <link to="#saveState"/>. Next time the machine is powered up, a
-        clean boot will occur. If @a remove is @c true the saved state file
-        is deleted.
+        Forgets the saved state of the virtual machine if it is currently
+        in the "Saved" state (previously created by <link to="#saveState"/>)
+        and deletes the file into which the machine state was saved.
+        Next time the machine is powered up, a clean boot will occur.
         <note>
           This operation is equivalent to resetting or powering off
@@ -6313,7 +6313,4 @@
         </result>
       </desc>
-      <param name="removeFile" type="boolean" dir="in">
-        <desc>If @c true remove the saved state file.</desc>
-      </param>
     </method>
 
Index: /trunk/src/VBox/Main/include/ConsoleImpl.h
===================================================================
--- /trunk/src/VBox/Main/include/ConsoleImpl.h	(revision 31217)
+++ /trunk/src/VBox/Main/include/ConsoleImpl.h	(revision 31218)
@@ -138,5 +138,5 @@
     STDMETHOD(SaveState)(IProgress **aProgress);
     STDMETHOD(AdoptSavedState)(IN_BSTR aSavedStateFile);
-    STDMETHOD(ForgetSavedState)(BOOL aRemove);
+    STDMETHOD(ForgetSavedState)();
     STDMETHOD(GetDeviceActivity)(DeviceType_T aDeviceType,
                                 DeviceActivity_T *aDeviceActivity);
Index: /trunk/src/VBox/Main/include/MachineImpl.h
===================================================================
--- /trunk/src/VBox/Main/include/MachineImpl.h	(revision 31217)
+++ /trunk/src/VBox/Main/include/MachineImpl.h	(revision 31218)
@@ -484,5 +484,5 @@
     STDMETHOD(SaveSettings)();
     STDMETHOD(DiscardSettings)();
-    STDMETHOD(Unregister) (BOOL fCloseMedia, ComSafeArrayOut(BSTR, aFiles));
+    STDMETHOD(Unregister) (BOOL fAutoCleanup, ComSafeArrayOut(BSTR, aFiles));
     STDMETHOD(Delete)();
     STDMETHOD(Export)(IAppliance *aAppliance, IVirtualSystemDescription **aDescription);
@@ -888,5 +888,4 @@
 
     // IInternalMachineControl methods
-    STDMETHOD(SetRemoveSavedState)(BOOL aRemove);
     STDMETHOD(UpdateState)(MachineState_T machineState);
     STDMETHOD(GetIPCId)(BSTR *id);
@@ -1025,6 +1024,4 @@
     HRESULT updateMachineStateOnClient();
 
-    HRESULT mRemoveSavedState;
-
     SnapshotData mSnapshotData;
 
