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);
 
