Index: /code/branches/objecthierarchy2/src/core/CommandExecutor.cc
===================================================================
--- /code/branches/objecthierarchy2/src/core/CommandExecutor.cc	(revision 2343)
+++ /code/branches/objecthierarchy2/src/core/CommandExecutor.cc	(revision 2344)
@@ -53,5 +53,5 @@
     }
 
-    ConsoleCommand& CommandExecutor::addConsoleCommandShortcut(ConsoleCommand* command)
+    ConsoleCommand& CommandExecutor::addConsoleCommandShortcut(ConsoleCommand* command, bool bDeleteAtExit)
     {
         std::map<std::string, ConsoleCommand*>::const_iterator it = CommandExecutor::getInstance().consoleCommandShortcuts_.find(command->getName());
@@ -61,4 +61,9 @@
         }
 
+        // Make sure we can also delete the external ConsoleCommands that don't belong to an Identifier
+        if (command && bDeleteAtExit)
+        {
+            CommandExecutor::getInstance().consoleCommandExternals_.insert(command);
+        }
 
         CommandExecutor::getInstance().consoleCommandShortcuts_[command->getName()] = command;
@@ -647,3 +652,10 @@
         }
     }
+
+    void CommandExecutor::destroyExternalCommands()
+    {
+        for (std::set<ConsoleCommand*>::const_iterator it = CommandExecutor::getInstance().consoleCommandExternals_.begin();
+            it != CommandExecutor::getInstance().consoleCommandExternals_.end(); ++it)
+            delete *it;
+    }
 }
Index: /code/branches/objecthierarchy2/src/core/CommandExecutor.h
===================================================================
--- /code/branches/objecthierarchy2/src/core/CommandExecutor.h	(revision 2343)
+++ /code/branches/objecthierarchy2/src/core/CommandExecutor.h	(revision 2344)
@@ -51,5 +51,5 @@
             static const CommandEvaluation& getLastEvaluation();
 
-            static ConsoleCommand& addConsoleCommandShortcut(ConsoleCommand* command);
+            static ConsoleCommand& addConsoleCommandShortcut(ConsoleCommand* command, bool bDeleteAtExit = false);
             static ConsoleCommand* getConsoleCommandShortcut(const std::string& name);
             static ConsoleCommand* getLowercaseConsoleCommandShortcut(const std::string& name);
@@ -68,4 +68,6 @@
             /** @brief Returns a const_iterator to the end of the map that stores all console commands with their names in lowercase. @return The const_iterator */
             static inline std::map<std::string, ConsoleCommand*>::const_iterator getLowercaseConsoleCommandShortcutMapEnd() { return CommandExecutor::getInstance().consoleCommandShortcuts_LC_.end(); }
+
+            static void destroyExternalCommands();
 
         private:
@@ -101,4 +103,5 @@
             std::map<std::string, ConsoleCommand*> consoleCommandShortcuts_;
             std::map<std::string, ConsoleCommand*> consoleCommandShortcuts_LC_;
+            std::set<ConsoleCommand*>              consoleCommandExternals_;
     }; // tolua_export
 } // tolua_export
Index: /code/branches/objecthierarchy2/src/core/CommandLine.cc
===================================================================
--- /code/branches/objecthierarchy2/src/core/CommandLine.cc	(revision 2343)
+++ /code/branches/objecthierarchy2/src/core/CommandLine.cc	(revision 2344)
@@ -83,9 +83,5 @@
     CommandLine::~CommandLine()
     {
-        for (std::map<std::string, CommandLineArgument*>::const_iterator it = cmdLineArgs_.begin();
-            it != cmdLineArgs_.end(); ++it)
-        {
-            delete it->second;
-        }
+        CommandLine::destroyAllArguments();
     }
 
@@ -98,4 +94,17 @@
         static CommandLine instance;
         return instance;
+    }
+
+    /**
+    @brief
+        Destroys all command line arguments. This should be called at the end
+        of main. Do not use before that.
+    */
+    void CommandLine::destroyAllArguments()
+    {
+        for (std::map<std::string, CommandLineArgument*>::const_iterator it = _getInstance().cmdLineArgs_.begin();
+            it != _getInstance().cmdLineArgs_.end(); ++it)
+            delete it->second;
+        _getInstance().cmdLineArgs_.clear();
     }
 
Index: /code/branches/objecthierarchy2/src/core/CommandLine.h
===================================================================
--- /code/branches/objecthierarchy2/src/core/CommandLine.h	(revision 2343)
+++ /code/branches/objecthierarchy2/src/core/CommandLine.h	(revision 2344)
@@ -155,4 +155,5 @@
         }
 
+        static void destroyAllArguments();
 
     private:
@@ -179,5 +180,5 @@
         //! Holds all pointers to the arguments and serves as a search map by name.
         std::map<std::string, CommandLineArgument*> cmdLineArgs_;
-        //! Search map by chortcut for the arguments.
+        //! Search map by shortcut for the arguments.
         std::map<std::string, CommandLineArgument*> cmdLineArgsShortcut_;
     };
Index: /code/branches/objecthierarchy2/src/core/ConsoleCommand.h
===================================================================
--- /code/branches/objecthierarchy2/src/core/ConsoleCommand.h	(revision 2343)
+++ /code/branches/objecthierarchy2/src/core/ConsoleCommand.h	(revision 2344)
@@ -64,5 +64,5 @@
 
 #define SetConsoleCommandShortcutGeneric(fakevariable, command) \
-    orxonox::ConsoleCommand& fakevariable = orxonox::CommandExecutor::addConsoleCommandShortcut(command)
+    orxonox::ConsoleCommand& fakevariable = orxonox::CommandExecutor::addConsoleCommandShortcut(command, true)
 
 
Index: /code/branches/objecthierarchy2/src/core/Core.cc
===================================================================
--- /code/branches/objecthierarchy2/src/core/Core.cc	(revision 2343)
+++ /code/branches/objecthierarchy2/src/core/Core.cc	(revision 2344)
@@ -46,4 +46,6 @@
     bool Core::bIsMaster_s      = false;
 
+    Core* Core::singletonRef_s = 0;
+
     /**
         @brief Constructor: Registers the object and sets the config-values.
@@ -53,6 +55,9 @@
     {
         RegisterRootObject(Core);
+
+        assert(singletonRef_s == 0);
+        singletonRef_s = this;
+
         this->setConfigValues();
-        isCreatingCoreSettings() = false;
     }
 
@@ -62,35 +67,6 @@
     Core::~Core()
     {
-        isCreatingCoreSettings() = true;
-    }
-
-    /**
-        @brief Returns true if the Core instance is not yet ready and the static functions have to return a default value.
-    */
-    bool& Core::isCreatingCoreSettings()
-    {
-        static bool bCreatingCoreSettings = true;
-        return bCreatingCoreSettings;
-    }
-
-    /**
-        @brief Returns a unique instance of Core.
-        @return The instance
-    */
-    Core& Core::getInstance()
-    {
-        // If bCreatingSoftDebugLevelObject is true, we're just about to create an instance of the DebugLevel class
-        //if (Core::isCreatingCoreSettings())
-        //{
-        //    isCreatingCoreSettings() = false;
-        //    //instance.setConfigValues();
-        //}
-
-        static bool firstTime = true;
-        if (firstTime)
-            isCreatingCoreSettings() = true;
-
-        static Core instance;
-        return instance;
+        assert(singletonRef_s);
+        singletonRef_s = 0;
     }
 
@@ -140,23 +116,18 @@
     int Core::getSoftDebugLevel(OutputHandler::OutputDevice device)
     {
-        if (!Core::isCreatingCoreSettings())
+        switch (device)
         {
-            switch (device)
-            {
-            case OutputHandler::LD_All:
-                return Core::getInstance().softDebugLevel_;
-            case OutputHandler::LD_Console:
-                return Core::getInstance().softDebugLevelConsole_;
-            case OutputHandler::LD_Logfile:
-                return Core::getInstance().softDebugLevelLogfile_;
-            case OutputHandler::LD_Shell:
-                return Core::getInstance().softDebugLevelShell_;
-            default:
-                assert(0);
-            }
+        case OutputHandler::LD_All:
+            return Core::getInstance().softDebugLevel_;
+        case OutputHandler::LD_Console:
+            return Core::getInstance().softDebugLevelConsole_;
+        case OutputHandler::LD_Logfile:
+            return Core::getInstance().softDebugLevelLogfile_;
+        case OutputHandler::LD_Shell:
+            return Core::getInstance().softDebugLevelShell_;
+        default:
+            assert(0);
+            return 2;
         }
-
-        // Return a constant value while we're creating the object
-        return 2;
     }
 
@@ -168,17 +139,14 @@
      void Core::setSoftDebugLevel(OutputHandler::OutputDevice device, int level)
      {
-        if (!Core::isCreatingCoreSettings())
-        {
-            if (device == OutputHandler::LD_All)
-                Core::getInstance().softDebugLevel_ = level;
-            else if (device == OutputHandler::LD_Console)
-                Core::getInstance().softDebugLevelConsole_ = level;
-            else if (device == OutputHandler::LD_Logfile)
-                Core::getInstance().softDebugLevelLogfile_ = level;
-            else if (device == OutputHandler::LD_Shell)
-                Core::getInstance().softDebugLevelShell_ = level;
+        if (device == OutputHandler::LD_All)
+            Core::getInstance().softDebugLevel_ = level;
+        else if (device == OutputHandler::LD_Console)
+            Core::getInstance().softDebugLevelConsole_ = level;
+        else if (device == OutputHandler::LD_Logfile)
+            Core::getInstance().softDebugLevelLogfile_ = level;
+        else if (device == OutputHandler::LD_Shell)
+            Core::getInstance().softDebugLevelShell_ = level;
 
-            OutputHandler::setSoftDebugLevel(device, level);
-        }
+        OutputHandler::setSoftDebugLevel(device, level);
      }
 
@@ -188,8 +156,5 @@
     const std::string& Core::getLanguage()
     {
-        if (!Core::isCreatingCoreSettings())
-            return Core::getInstance().language_;
-
-        return Language::getLanguage().defaultLanguage_;
+        return Core::getInstance().language_;
     }
 
Index: /code/branches/objecthierarchy2/src/core/Core.h
===================================================================
--- /code/branches/objecthierarchy2/src/core/Core.h	(revision 2343)
+++ /code/branches/objecthierarchy2/src/core/Core.h	(revision 2344)
@@ -40,4 +40,5 @@
 #include "CorePrereqs.h"
 
+#include <cassert>
 #include "OrxonoxClass.h"
 #include "util/OutputHandler.h"
@@ -49,14 +50,16 @@
     {
         public:
-            static Core& getInstance();
-            static bool& isCreatingCoreSettings();
+            Core();
+            ~Core();
             void setConfigValues();
             void debugLevelChanged();
             void languageChanged();
 
-            static int getSoftDebugLevel(OutputHandler::OutputDevice device = OutputHandler::LD_All);
-            static void setSoftDebugLevel(OutputHandler::OutputDevice device, int level);
+            static Core& getInstance() { assert(singletonRef_s); return *singletonRef_s; }
+
+            static int   getSoftDebugLevel(OutputHandler::OutputDevice device = OutputHandler::LD_All);
+            static void  setSoftDebugLevel(OutputHandler::OutputDevice device, int level);
             static const std::string& getLanguage();
-            static void resetLanguage();
+            static void  resetLanguage();
 
             // fast access global variables.
@@ -73,9 +76,6 @@
 
         private:
+            Core(const Core&);
             void resetLanguageIntern();
-
-            Core();
-            Core(const Core& other);
-            virtual ~Core();
 
             int softDebugLevel_;                            //!< The debug level
@@ -90,4 +90,6 @@
             static bool bIsStandalone_s;
             static bool bIsMaster_s;
+
+            static Core* singletonRef_s;
     };
 }
Index: /code/branches/objecthierarchy2/src/core/CorePrereqs.h
===================================================================
--- /code/branches/objecthierarchy2/src/core/CorePrereqs.h	(revision 2343)
+++ /code/branches/objecthierarchy2/src/core/CorePrereqs.h	(revision 2344)
@@ -133,4 +133,5 @@
   class LanguageEntry;
   class Loader;
+  class LuaBind;
   class MetaObjectList;
   class MetaObjectListElement;
Index: /code/branches/objecthierarchy2/src/core/Identifier.cc
===================================================================
--- /code/branches/objecthierarchy2/src/core/Identifier.cc	(revision 2343)
+++ /code/branches/objecthierarchy2/src/core/Identifier.cc	(revision 2344)
@@ -93,4 +93,15 @@
         for (std::map<std::string, XMLPortObjectContainer*>::iterator it = this->xmlportObjectContainers_.begin(); it != this->xmlportObjectContainers_.end(); ++it)
             delete (it->second);
+        for (std::vector<Functor*>::iterator it = this->constructionCallbacks_.begin(); it != this->constructionCallbacks_.end(); ++it)
+            delete *it;
+    }
+
+    /**
+        @brief Returns the identifier map with the names as received by typeid(). This is only used internally.
+    */
+    std::map<std::string, Identifier*>& Identifier::getTypeIDIdentifierMap()
+    {
+        static std::map<std::string, Identifier*> identifiers;    //!< The map to store all Identifiers.
+        return identifiers;
     }
 
@@ -103,8 +114,7 @@
     Identifier* Identifier::getIdentifierSingleton(const std::string& name, Identifier* proposal)
     {
-        static std::map<std::string, Identifier*> identifiers;    //!< The map to store all Identifiers.
-        std::map<std::string, Identifier*>::const_iterator it = identifiers.find(name);
-
-        if (it != identifiers.end())
+        std::map<std::string, Identifier*>::const_iterator it = getTypeIDIdentifierMap().find(name);
+
+        if (it != getTypeIDIdentifierMap().end())
         {
             // There is already an entry: return it and delete the proposal
@@ -115,5 +125,5 @@
         {
             // There is no entry: put the proposal into the map and return it
-            identifiers[name] = proposal;
+            getTypeIDIdentifierMap()[name] = proposal;
             return proposal;
         }
@@ -192,5 +202,5 @@
     void Identifier::destroyAllIdentifiers()
     {
-        for (std::map<std::string, Identifier*>::iterator it = Identifier::getIdentifierMapIntern().begin(); it != Identifier::getIdentifierMapIntern().end(); ++it)
+        for (std::map<std::string, Identifier*>::iterator it = Identifier::getTypeIDIdentifierMap().begin(); it != Identifier::getTypeIDIdentifierMap().end(); ++it)
             delete (it->second);
     }
Index: /code/branches/objecthierarchy2/src/core/Identifier.h
===================================================================
--- /code/branches/objecthierarchy2/src/core/Identifier.h	(revision 2343)
+++ /code/branches/objecthierarchy2/src/core/Identifier.h	(revision 2344)
@@ -257,4 +257,6 @@
             void initializeClassHierarchy(std::set<const Identifier*>* parents, bool bRootClass);
 
+            static void destroyAllIdentifiers();
+
         protected:
             Identifier();
@@ -299,7 +301,7 @@
             }
 
+            static std::map<std::string, Identifier*>& getTypeIDIdentifierMap();
+
             void initialize(std::set<const Identifier*>* parents);
-
-            static void destroyAllIdentifiers();
 
             std::set<const Identifier*> parents_;                          //!< The parents of the class the Identifier belongs to
Index: /code/branches/objecthierarchy2/src/core/Language.cc
===================================================================
--- /code/branches/objecthierarchy2/src/core/Language.cc	(revision 2343)
+++ /code/branches/objecthierarchy2/src/core/Language.cc	(revision 2344)
@@ -87,4 +87,7 @@
     // ###        Language         ###
     // ###############################
+
+    Language* Language::singletonRef_s = 0;
+
     /**
         @brief Constructor: Reads the default language file and sets some values.
@@ -92,4 +95,7 @@
     Language::Language()
     {
+        assert(singletonRef_s == 0);
+        singletonRef_s = this;
+
         this->defaultLanguage_ = "default";
         this->defaultLocalisation_ = "ERROR: LANGUAGE ENTRY DOESN'T EXIST!";
@@ -106,14 +112,7 @@
         for (std::map<std::string, LanguageEntry*>::iterator it = this->languageEntries_.begin(); it != this->languageEntries_.end(); ++it)
             delete (it->second);
-    }
-
-    /**
-        @brief Returns a reference to the only existing instance of the Language class and calls the setConfigValues() function.
-        @return The reference to the only existing instance
-    */
-    Language& Language::getLanguage()
-    {
-        static Language instance = Language();
-        return instance;
+
+        assert(singletonRef_s);
+        singletonRef_s = 0;
     }
 
Index: /code/branches/objecthierarchy2/src/core/Language.h
===================================================================
--- /code/branches/objecthierarchy2/src/core/Language.h	(revision 2343)
+++ /code/branches/objecthierarchy2/src/core/Language.h	(revision 2344)
@@ -50,4 +50,5 @@
 #include <map>
 #include <string>
+#include <cassert>
 
 #define AddLanguageEntry(label, fallbackstring) \
@@ -116,12 +117,13 @@
 
         public:
-            static Language& getLanguage();
+            Language();
+            ~Language();
+
+            static Language& getLanguage() { assert(singletonRef_s); return *singletonRef_s; }
             void addEntry(const LanguageEntryLabel& label, const std::string& entry);
             const std::string& getLocalisation(const LanguageEntryLabel& label) const;
 
         private:
-            Language();
-            Language(const Language& language);     // don't copy
-            virtual ~Language();
+            Language(const Language&);
 
             void readDefaultLanguageFile();
@@ -134,4 +136,6 @@
             std::string defaultLocalisation_;                       //!< The returned string, if an entry unavailable entry is requested
             std::map<std::string, LanguageEntry*> languageEntries_; //!< A map to store all LanguageEntry objects and their labels
+
+            static Language* singletonRef_s;
     };
 }
Index: /code/branches/objecthierarchy2/src/core/Loader.cc
===================================================================
--- /code/branches/objecthierarchy2/src/core/Loader.cc	(revision 2343)
+++ /code/branches/objecthierarchy2/src/core/Loader.cc	(revision 2344)
@@ -120,8 +120,8 @@
 
         // let Lua work this out:
-        LuaBind* lua = LuaBind::getInstance();
-        lua->clearLuaOutput();
-        lua->loadFile(file->getFilename(), true);
-        lua->run();
+        LuaBind& lua = LuaBind::getInstance();
+        lua.clearLuaOutput();
+        lua.loadFile(file->getFilename(), true);
+        lua.run();
 
         try
@@ -135,5 +135,5 @@
             ticpp::Document xmlfile;
             //xmlfile.ToDocument();
-            xmlfile.Parse(lua->getLuaOutput(), true);
+            xmlfile.Parse(lua.getLuaOutput(), true);
 
             ticpp::Element rootElement;
Index: /code/branches/objecthierarchy2/src/core/LuaBind.cc
===================================================================
--- /code/branches/objecthierarchy2/src/core/LuaBind.cc	(revision 2343)
+++ /code/branches/objecthierarchy2/src/core/LuaBind.cc	(revision 2344)
@@ -40,8 +40,11 @@
 namespace orxonox
 {
-  LuaBind* LuaBind::singletonRef = NULL;
+  LuaBind* LuaBind::singletonRef_s = NULL;
 
   LuaBind::LuaBind()
   {
+    assert(LuaBind::singletonRef_s == 0);
+    LuaBind::singletonRef_s = this;
+
     luaState_ = lua_open();
     luaSource_ = "";
Index: /code/branches/objecthierarchy2/src/core/LuaBind.h
===================================================================
--- /code/branches/objecthierarchy2/src/core/LuaBind.h	(revision 2343)
+++ /code/branches/objecthierarchy2/src/core/LuaBind.h	(revision 2344)
@@ -42,4 +42,5 @@
 }
 
+#include <cassert>
 #include <list>
 #include <string>
@@ -58,6 +59,8 @@
 
     public:
-      inline static LuaBind* getInstance() { if (!LuaBind::singletonRef) LuaBind::singletonRef = new LuaBind(); return LuaBind::singletonRef; } // tolua_export
-      inline ~LuaBind() { LuaBind::singletonRef = NULL; };
+      LuaBind();
+      inline ~LuaBind() { assert(singletonRef_s); LuaBind::singletonRef_s = NULL; };
+
+      inline static LuaBind& getInstance() { assert(singletonRef_s); return *LuaBind::singletonRef_s; } // tolua_export
 
     void loadFile(std::string filename, bool luaTags);
@@ -83,6 +86,5 @@
 
     private:
-      LuaBind();
-      static LuaBind* singletonRef;
+      static LuaBind* singletonRef_s;
 
       std::string luaSource_;
Index: /code/branches/objecthierarchy2/src/core/RootGameState.cc
===================================================================
--- /code/branches/objecthierarchy2/src/core/RootGameState.cc	(revision 2343)
+++ /code/branches/objecthierarchy2/src/core/RootGameState.cc	(revision 2344)
@@ -31,5 +31,4 @@
 #include "util/Debug.h"
 #include "util/Exception.h"
-#include "Core.h"
 #include "Clock.h"
 #include "CommandLine.h"
@@ -137,7 +136,4 @@
             Clock clock;
 
-            // create the Core settings to configure the output level
-            Core::getInstance();
-
             this->activate();
 
Index: /code/branches/objecthierarchy2/src/core/RootGameState.h
===================================================================
--- /code/branches/objecthierarchy2/src/core/RootGameState.h	(revision 2343)
+++ /code/branches/objecthierarchy2/src/core/RootGameState.h	(revision 2344)
@@ -48,5 +48,5 @@
         void gotoState(const std::string& name);
 
-        std::string           stateRequest_;
+        std::string stateRequest_;
     };
 }
Index: /code/branches/objecthierarchy2/src/core/XMLPort.h
===================================================================
--- /code/branches/objecthierarchy2/src/core/XMLPort.h	(revision 2343)
+++ /code/branches/objecthierarchy2/src/core/XMLPort.h	(revision 2344)
@@ -43,4 +43,5 @@
 #include "CorePrereqs.h"
 
+#include <cassert>
 #include "util/Debug.h"
 #include "util/Exception.h"
@@ -327,4 +328,12 @@
                 this->loadexecutor_ = loadexecutor;
                 this->saveexecutor_ = saveexecutor;
+            }
+
+            ~XMLPortClassParamContainer()
+            {
+                assert(this->loadexecutor_);
+                delete this->loadexecutor_;
+                if (this->saveexecutor_)
+                    delete this->saveexecutor_;
             }
 
@@ -471,4 +480,12 @@
                 this->bApplyLoaderMask_ = bApplyLoaderMask;
                 this->bLoadBefore_ = bLoadBefore;
+            }
+
+            ~XMLPortClassObjectContainer()
+            {
+                assert(this->loadexecutor_);
+                delete this->loadexecutor_;
+                if (this->saveexecutor_)
+                    delete this->saveexecutor_;
             }
 
Index: /code/branches/objecthierarchy2/src/core/input/Button.cc
===================================================================
--- /code/branches/objecthierarchy2/src/core/input/Button.cc	(revision 2343)
+++ /code/branches/objecthierarchy2/src/core/input/Button.cc	(revision 2344)
@@ -59,4 +59,5 @@
         nCommands_[1]=0;
         nCommands_[2]=0;
+        this->configContainer_ = 0;
         clear();
     }
@@ -80,4 +81,8 @@
             }
         }
+
+        if (this->configContainer_)
+            delete this->configContainer_;
+        this->configContainer_ = 0;
     }
 
Index: /code/branches/objecthierarchy2/src/core/input/InputBuffer.cc
===================================================================
--- /code/branches/objecthierarchy2/src/core/input/InputBuffer.cc	(revision 2343)
+++ /code/branches/objecthierarchy2/src/core/input/InputBuffer.cc	(revision 2344)
@@ -73,4 +73,11 @@
     }
 
+    InputBuffer::~InputBuffer()
+    {
+        for (std::list<BaseInputBufferListenerTuple*>::const_iterator it = this->listeners_.begin();
+            it != this->listeners_.end(); ++it)
+            delete *it;
+    }
+
     void InputBuffer::setConfigValues()
     {
Index: /code/branches/objecthierarchy2/src/core/input/InputBuffer.h
===================================================================
--- /code/branches/objecthierarchy2/src/core/input/InputBuffer.h	(revision 2343)
+++ /code/branches/objecthierarchy2/src/core/input/InputBuffer.h	(revision 2344)
@@ -79,4 +79,5 @@
         public:
             InputBuffer();
+            ~InputBuffer();
             InputBuffer(const std::string allowedChars);
 
Index: /code/branches/objecthierarchy2/src/orxonox/LevelManager.cc
===================================================================
--- /code/branches/objecthierarchy2/src/orxonox/LevelManager.cc	(revision 2343)
+++ /code/branches/objecthierarchy2/src/orxonox/LevelManager.cc	(revision 2344)
@@ -42,6 +42,4 @@
         assert(singletonRef_s == 0);
         singletonRef_s = this;
-
-        PlayerManager::getInstance(); // ensure existence of PlayerManager
     }
 
Index: /code/branches/objecthierarchy2/src/orxonox/Main.cc
===================================================================
--- /code/branches/objecthierarchy2/src/orxonox/Main.cc	(revision 2343)
+++ /code/branches/objecthierarchy2/src/orxonox/Main.cc	(revision 2344)
@@ -43,4 +43,8 @@
 #include "core/ConfigFileManager.h"
 #include "core/CommandLine.h"
+#include "core/CommandExecutor.h"
+#include "core/Identifier.h"
+#include "core/Core.h"
+#include "core/Language.h"
 
 #include "gamestates/GSRoot.h"
@@ -92,5 +96,6 @@
 
     // create a signal handler (only works for linux)
-    SignalHandler::getInstance()->doCatch(argv[0], "orxonox.log");
+    SignalHandler signalHandler;
+    signalHandler.doCatch(argv[0], "orxonox.log");
 
     // Parse command line arguments
@@ -109,29 +114,44 @@
     ConfigFileManager* configFileManager = new ConfigFileManager();
     configFileManager->setFilename(ConfigFileType::Settings, CommandLine::getValue("settingsFile").getString());
+    // create the Core settings to configure the output level
+    Language* language = new Language();
+    Core*     core     = new Core();
 
-    // create the gamestates
-    GSRoot root;
-    GSGraphics graphics;
-    GSStandalone standalone;
-    GSServer server;
-    GSClient client;
-    GSDedicated dedicated;
-    GSGUI gui;
-    GSIOConsole ioConsole;
+    // put GameStates in its own scope so we can destroy the identifiers at the end of main().
+    {
+        // create the gamestates
+        GSRoot root;
+        GSGraphics graphics;
+        GSStandalone standalone;
+        GSServer server;
+        GSClient client;
+        GSDedicated dedicated;
+        GSGUI gui;
+        GSIOConsole ioConsole;
 
-    // make the hierarchy
-    root.addChild(&graphics);
-    graphics.addChild(&standalone);
-    graphics.addChild(&server);
-    graphics.addChild(&client);
-    graphics.addChild(&gui);
-    root.addChild(&ioConsole);
-    root.addChild(&dedicated);
+        // make the hierarchy
+        root.addChild(&graphics);
+        graphics.addChild(&standalone);
+        graphics.addChild(&server);
+        graphics.addChild(&client);
+        graphics.addChild(&gui);
+        root.addChild(&ioConsole);
+        root.addChild(&dedicated);
 
-    // Here happens the game
-    root.start();
+        // Here happens the game
+        root.start();
+    }
 
-    // Destroy ConfigFileManager again.
+    // destroy singletons
+    delete core;
+    delete language;
     delete configFileManager;
+
+    // Clean up class hierarchy stuff (identifiers, xmlport, configvalue, consolecommand)
+    Identifier::destroyAllIdentifiers();
+    // destroy command line arguments
+    CommandLine::destroyAllArguments();
+    // Also delete external console command that don't belong to an Identifier
+    CommandExecutor::destroyExternalCommands();
 
     return 0;
Index: /code/branches/objecthierarchy2/src/orxonox/PlayerManager.cc
===================================================================
--- /code/branches/objecthierarchy2/src/orxonox/PlayerManager.cc	(revision 2343)
+++ /code/branches/objecthierarchy2/src/orxonox/PlayerManager.cc	(revision 2344)
@@ -38,7 +38,12 @@
 namespace orxonox
 {
+    PlayerManager* PlayerManager::singletonRef_s = 0;
+
     PlayerManager::PlayerManager()
     {
         RegisterRootObject(PlayerManager);
+
+        assert(singletonRef_s == 0);
+        singletonRef_s = this;
 
         this->getConnectedClients();
@@ -47,10 +52,6 @@
     PlayerManager::~PlayerManager()
     {
-    }
-
-    PlayerManager& PlayerManager::getInstance()
-    {
-        static PlayerManager instance;
-        return instance;
+        assert(singletonRef_s);
+        singletonRef_s = 0;
     }
 
Index: /code/branches/objecthierarchy2/src/orxonox/PlayerManager.h
===================================================================
--- /code/branches/objecthierarchy2/src/orxonox/PlayerManager.h	(revision 2343)
+++ /code/branches/objecthierarchy2/src/orxonox/PlayerManager.h	(revision 2344)
@@ -43,5 +43,6 @@
             virtual ~PlayerManager();
 
-            static PlayerManager& getInstance();
+            static PlayerManager& getInstance()
+            { assert(singletonRef_s); return *singletonRef_s; }
 
             PlayerInfo* getClient(unsigned int clientID) const;
@@ -54,4 +55,6 @@
 
             std::map<unsigned int, PlayerInfo*> clients_;
+
+            static PlayerManager* singletonRef_s;
     };
 }
Index: /code/branches/objecthierarchy2/src/orxonox/Settings.cc
===================================================================
--- /code/branches/objecthierarchy2/src/orxonox/Settings.cc	(revision 2343)
+++ /code/branches/objecthierarchy2/src/orxonox/Settings.cc	(revision 2344)
@@ -83,5 +83,5 @@
         }
 
-        LuaBind::getInstance()->setIncludePath(this->dataPath_);
+        LuaBind::getInstance().setIncludePath(this->dataPath_);
     }
 
Index: /code/branches/objecthierarchy2/src/orxonox/gamestates/GSGraphics.cc
===================================================================
--- /code/branches/objecthierarchy2/src/orxonox/gamestates/GSGraphics.cc	(revision 2343)
+++ /code/branches/objecthierarchy2/src/orxonox/gamestates/GSGraphics.cc	(revision 2344)
@@ -164,5 +164,6 @@
         FunctorMember<GSGraphics>* functor1 = createFunctor(&GSGraphics::printScreen);
         functor1->setObject(this);
-        CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(functor1, "printScreen"));
+        ccPrintScreen_ = createConsoleCommand(functor1, "printScreen");
+        CommandExecutor::addConsoleCommandShortcut(ccPrintScreen_);
     }
 
@@ -170,4 +171,6 @@
     {
         using namespace Ogre;
+
+        delete this->ccPrintScreen_;
 
         // remove our WindowEventListener first to avoid bad calls after the window has been destroyed
Index: /code/branches/objecthierarchy2/src/orxonox/gamestates/GSGraphics.h
===================================================================
--- /code/branches/objecthierarchy2/src/orxonox/gamestates/GSGraphics.h	(revision 2343)
+++ /code/branches/objecthierarchy2/src/orxonox/gamestates/GSGraphics.h	(revision 2344)
@@ -112,4 +112,7 @@
         unsigned int          detailLevelParticle_;      //!< Detail level of particle effects (0: off, 1: low, 2: normal, 3: high)
         std::string           defaultMasterKeybindings_; //!< Filename of default master keybindings.
+
+        // console commands
+        ConsoleCommand*       ccPrintScreen_;
     };
 }
Index: /code/branches/objecthierarchy2/src/orxonox/gamestates/GSLevel.cc
===================================================================
--- /code/branches/objecthierarchy2/src/orxonox/gamestates/GSLevel.cc	(revision 2343)
+++ /code/branches/objecthierarchy2/src/orxonox/gamestates/GSLevel.cc	(revision 2344)
@@ -47,4 +47,5 @@
 #include "CameraManager.h"
 #include "LevelManager.h"
+#include "PlayerManager.h"
 #include "Settings.h"
 
@@ -99,4 +100,5 @@
             // create the global LevelManager
             this->levelManager_ = new LevelManager();
+            this->playerManager_ = new PlayerManager();
 
             // reset game speed to normal
@@ -114,8 +116,10 @@
             FunctorMember<GSLevel>* functor1 = createFunctor(&GSLevel::keybind);
             functor1->setObject(this);
-            CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(functor1, "keybind"));
+            ccKeybind_ = createConsoleCommand(functor1, "keybind");
+            CommandExecutor::addConsoleCommandShortcut(ccKeybind_);
             FunctorMember<GSLevel>* functor2 = createFunctor(&GSLevel::tkeybind);
             functor2->setObject(this);
-            CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(functor2, "tkeybind"));
+            ccTkeybind_ = createConsoleCommand(functor2, "tkeybind");
+            CommandExecutor::addConsoleCommandShortcut(ccTkeybind_);
             // set our console command as callback for the key detector
             InputManager::getInstance().setKeyDetectorCallback(std::string("keybind ") + keyDetectorCallbackCode_);
@@ -130,5 +134,6 @@
             FunctorMember<GSLevel>* functor = createFunctor(&GSLevel::setTimeFactor);
             functor->setObject(this);
-            CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(functor, "setTimeFactor")).accessLevel(AccessLevel::Offline).defaultValue(0, 1.0);;
+            ccSetTimeFactor_ = createConsoleCommand(functor, "setTimeFactor");
+            CommandExecutor::addConsoleCommandShortcut(ccSetTimeFactor_).accessLevel(AccessLevel::Offline).defaultValue(0, 1.0);;
         }
     }
@@ -136,4 +141,9 @@
     void GSLevel::leave()
     {
+        // destroy console commands
+        delete this->ccKeybind_;
+        delete this->ccSetTimeFactor_;
+        delete this->ccTkeybind_;
+
         // this call will delete every BaseObject!
         // But currently this will call methods of objects that exist no more
@@ -156,4 +166,7 @@
         if (this->levelManager_)
             delete this->levelManager_;
+
+        if (this->playerManager_)
+            delete this->playerManager_;
 
         if (Core::showsGraphics())
Index: /code/branches/objecthierarchy2/src/orxonox/gamestates/GSLevel.h
===================================================================
--- /code/branches/objecthierarchy2/src/orxonox/gamestates/GSLevel.h	(revision 2343)
+++ /code/branches/objecthierarchy2/src/orxonox/gamestates/GSLevel.h	(revision 2344)
@@ -70,4 +70,5 @@
         CameraManager*        cameraManager_;
         LevelManager*         levelManager_;
+        PlayerManager*        playerManager_;
 
         //##### ConfigValues #####
@@ -75,4 +76,9 @@
         //! Filename of default keybindings.
         std::string           defaultKeybindings_;
+
+        // console commands
+        ConsoleCommand*       ccKeybind_;
+        ConsoleCommand*       ccTkeybind_;
+        ConsoleCommand*       ccSetTimeFactor_;
 
     private:
Index: /code/branches/objecthierarchy2/src/orxonox/gamestates/GSRoot.cc
===================================================================
--- /code/branches/objecthierarchy2/src/orxonox/gamestates/GSRoot.cc	(revision 2343)
+++ /code/branches/objecthierarchy2/src/orxonox/gamestates/GSRoot.cc	(revision 2344)
@@ -40,4 +40,5 @@
 #include "core/TclBind.h"
 #include "core/TclThreadManager.h"
+#include "core/LuaBind.h"
 #include "tools/Timer.h"
 #include "objects/Tickable.h"
@@ -87,4 +88,7 @@
         // creates the class hierarchy for all classes with factories
         Factory::createClassHierarchy();
+
+        // Create the lua interface
+        this->luaBind_ = new LuaBind();
 
         // instantiate Settings class
@@ -117,15 +121,19 @@
         FunctorMember<GSRoot>* functor1 = createFunctor(&GSRoot::exitGame);
         functor1->setObject(this);
-        CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(functor1, "exit"));
+        ccExit_ = createConsoleCommand(functor1, "exit");
+        CommandExecutor::addConsoleCommandShortcut(ccExit_);
 
         // add console commands
         FunctorMember01<GameStateBase, const std::string&>* functor2 = createFunctor(&GameStateBase::requestState);
         functor2->setObject(this);
-        CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(functor2, "selectGameState"));
+        ccSelectGameState_ = createConsoleCommand(functor2, "selectGameState");
+        CommandExecutor::addConsoleCommandShortcut(ccSelectGameState_);
     }
 
     void GSRoot::leave()
     {
-        // TODO: remove and destroy console commands
+        // destroy console commands
+        delete this->ccExit_;
+        delete this->ccSelectGameState_;
 
         delete this->shell_;
@@ -133,6 +141,6 @@
         delete this->tclBind_;
 
-        delete settings_;
-
+        delete this->settings_;
+        delete this->luaBind_;
     }
 
Index: /code/branches/objecthierarchy2/src/orxonox/gamestates/GSRoot.h
===================================================================
--- /code/branches/objecthierarchy2/src/orxonox/gamestates/GSRoot.h	(revision 2343)
+++ /code/branches/objecthierarchy2/src/orxonox/gamestates/GSRoot.h	(revision 2344)
@@ -59,4 +59,9 @@
         TclThreadManager*     tclThreadManager_;
         Shell*                shell_;
+        LuaBind*              luaBind_;
+
+        // console commands
+        ConsoleCommand*       ccExit_;
+        ConsoleCommand*       ccSelectGameState_;
     };
 }
Index: /code/branches/objecthierarchy2/src/orxonox/gui/GUIManager.cc
===================================================================
--- /code/branches/objecthierarchy2/src/orxonox/gui/GUIManager.cc	(revision 2343)
+++ /code/branches/objecthierarchy2/src/orxonox/gui/GUIManager.cc	(revision 2344)
@@ -96,13 +96,13 @@
         {
             // destroy our own tolua interfaces
-	        //lua_pushnil(luaState_);
-	        //lua_setglobal(luaState_, "Orxonox");
-	        //lua_pushnil(luaState_);
-	        //lua_setglobal(luaState_, "Core");
+	        lua_pushnil(luaState_);
+	        lua_setglobal(luaState_, "Orxonox");
+	        lua_pushnil(luaState_);
+	        lua_setglobal(luaState_, "Core");
             // TODO: deleting the script module fails an assertation.
             // However there is not much we can do about it since it occurs too when
             // we don't open Core or Orxonox. Might be a CEGUI issue.
             // The memory leak is not a problem anyway..
-            //delete scriptModule_;
+            delete scriptModule_;
         }
 
Index: /code/branches/objecthierarchy2/src/orxonox/objects/Script.cc
===================================================================
--- /code/branches/objecthierarchy2/src/orxonox/objects/Script.cc	(revision 2343)
+++ /code/branches/objecthierarchy2/src/orxonox/objects/Script.cc	(revision 2344)
@@ -64,7 +64,7 @@
   void Script::execute()
   {
-    LuaBind* lua = LuaBind::getInstance();
-    lua->loadString(this->code_);
-    lua->run();
+    LuaBind& lua = LuaBind::getInstance();
+    lua.loadString(this->code_);
+    lua.run();
   }
 }
Index: /code/branches/objecthierarchy2/src/util/SignalHandler.cc
===================================================================
--- /code/branches/objecthierarchy2/src/util/SignalHandler.cc	(revision 2343)
+++ /code/branches/objecthierarchy2/src/util/SignalHandler.cc	(revision 2344)
@@ -35,5 +35,4 @@
 #include "Debug.h"
 
-#include <cassert>
 #include <iostream>
 #include <cstdlib>
@@ -42,5 +41,5 @@
 namespace orxonox
 {
-    SignalHandler * SignalHandler::singletonRef = NULL;
+    SignalHandler* SignalHandler::singletonRef_s = NULL;
 }
 
@@ -133,5 +132,5 @@
     void SignalHandler::sigHandler( int sig )
     {
-      for ( SignalCallbackList::iterator it = SignalHandler::getInstance()->callbackList.begin(); it != SignalHandler::getInstance()->callbackList.end(); it++  )
+      for ( SignalCallbackList::iterator it = SignalHandler::getInstance().callbackList.begin(); it != SignalHandler::getInstance().callbackList.end(); it++  )
       {
         (*(it->cb))( it->someData );
@@ -184,5 +183,5 @@
       if ( sigPid == 0 )
       {
-        getInstance()->dontCatch();
+        getInstance().dontCatch();
         // wait for message from parent when it has attached gdb
         int someData;
@@ -237,5 +236,5 @@
 
       char cmd[256];
-      snprintf( cmd, 256, "file %s\nattach %d\nc\n", getInstance()->appName.c_str(), sigPid );
+      snprintf( cmd, 256, "file %s\nattach %d\nc\n", getInstance().appName.c_str(), sigPid );
       write( gdbIn[1], cmd, strlen(cmd) );
 
@@ -331,9 +330,9 @@
       bt.insert(0, timeString);
 
-      FILE * f = fopen( getInstance()->filename.c_str(), "a" );
+      FILE * f = fopen( getInstance().filename.c_str(), "a" );
 
       if ( !f )
       {
-        perror( ( std::string( "could not append to " ) + getInstance()->filename ).c_str() );
+        perror( ( std::string( "could not append to " ) + getInstance().filename ).c_str() );
         exit(EXIT_FAILURE);
       }
@@ -341,5 +340,5 @@
       if ( fwrite( bt.c_str(), 1, bt.length(), f ) != bt.length() )
       {
-        COUT(0) << "could not write " << bt.length() << " byte to " << getInstance()->filename << std::endl;
+        COUT(0) << "could not write " << bt.length() << " byte to " << getInstance().filename << std::endl;
         exit(EXIT_FAILURE);
       }
Index: /code/branches/objecthierarchy2/src/util/SignalHandler.h
===================================================================
--- /code/branches/objecthierarchy2/src/util/SignalHandler.h	(revision 2343)
+++ /code/branches/objecthierarchy2/src/util/SignalHandler.h	(revision 2344)
@@ -37,4 +37,5 @@
 #include "UtilPrereqs.h"
 
+#include <cassert>
 #include <list>
 #include <string>
@@ -68,9 +69,8 @@
     class SignalHandler
     {
-    private:
-        SignalHandler();
     public:
-        inline static SignalHandler* getInstance() { if (!SignalHandler::singletonRef) SignalHandler::singletonRef = new SignalHandler(); return SignalHandler::singletonRef; }
-        ~SignalHandler(){ SignalHandler::singletonRef = NULL; }
+        SignalHandler()  { assert(SignalHandler::singletonRef_s == 0); SignalHandler::singletonRef_s = this; }
+        ~SignalHandler() { assert(SignalHandler::singletonRef_s != 0); SignalHandler::singletonRef_s = NULL; }
+        inline static SignalHandler& getInstance() { assert(SignalHandler::singletonRef_s); return *SignalHandler::singletonRef_s; }
 
         void registerCallback( SignalCallback cb, void * someData );
@@ -87,5 +87,5 @@
         SignalCallbackList callbackList;
 
-        static SignalHandler * singletonRef;
+        static SignalHandler* singletonRef_s;
 
         std::string appName;
@@ -104,11 +104,13 @@
     {
     public:
-        inline static SignalHandler* getInstance() { if (!SignalHandler::singletonRef) SignalHandler::singletonRef = new SignalHandler(); return SignalHandler::singletonRef; };
-        void doCatch( const std::string & appName, const std::string & filename ) {};
-        void dontCatch() {};
-        void registerCallback( SignalCallback cb, void * someData ) {};
+        SignalHandler()  { assert(SignalHandler::singletonRef_s == 0); SignalHandler::singletonRef_s = this; }
+        ~SignalHandler() { assert(SignalHandler::singletonRef_s != 0); SignalHandler::singletonRef_s = 0; }
+        inline static SignalHandler& getInstance() { assert(SignalHandler::singletonRef_s); return *SignalHandler::singletonRef_s; }
+        void doCatch( const std::string & appName, const std::string & filename ) {}
+        void dontCatch() {}
+        void registerCallback( SignalCallback cb, void * someData ) {}
 
     private:
-        static SignalHandler * singletonRef;
+        static SignalHandler* singletonRef_s;
     };
 }
