Index: code/branches/core5/src/libraries/core/CorePrereqs.h
===================================================================
--- code/branches/core5/src/libraries/core/CorePrereqs.h	(revision 5803)
+++ code/branches/core5/src/libraries/core/CorePrereqs.h	(revision 5804)
@@ -155,4 +155,6 @@
     class ShellListener;
     template <class T>
+    class SmartPtr;
+    template <class T>
     class SubclassIdentifier;
     class TclBind;
@@ -162,4 +164,6 @@
     class TclThreadManager;
     class Template;
+    template <class T>
+    class WeakPtr;
     class WindowEventListener;
     class XMLFile;
Index: code/branches/core5/src/libraries/core/OrxonoxClass.cc
===================================================================
--- code/branches/core5/src/libraries/core/OrxonoxClass.cc	(revision 5803)
+++ code/branches/core5/src/libraries/core/OrxonoxClass.cc	(revision 5804)
@@ -52,4 +52,9 @@
     OrxonoxClass::~OrxonoxClass()
     {
+//        if (!this->requestedDestruction_)
+//            COUT(2) << "Warning: Destroyed object without destroy() (" << this->getIdentifier()->getName() << ")" << std::endl;
+
+        assert(this->referenceCount_ == 0);
+
         delete this->metaList_;
 
@@ -62,7 +67,6 @@
     void OrxonoxClass::destroy()
     {
-        if (this->referenceCount_ > 0)
-            this->requestedDestruction_ = true;
-        else
+        this->requestedDestruction_ = true;
+        if (this->referenceCount_ == 0)
             delete this;
     }
Index: code/branches/core5/src/libraries/core/OrxonoxClass.h
===================================================================
--- code/branches/core5/src/libraries/core/OrxonoxClass.h	(revision 5803)
+++ code/branches/core5/src/libraries/core/OrxonoxClass.h	(revision 5804)
@@ -54,4 +54,7 @@
         template <class T>
         friend class ClassIdentifier;
+
+        template <class T>
+        friend class SmartPtr;
 
         public:
Index: code/branches/core5/src/libraries/core/SmartPtr.h
===================================================================
--- code/branches/core5/src/libraries/core/SmartPtr.h	(revision 5804)
+++ code/branches/core5/src/libraries/core/SmartPtr.h	(revision 5804)
@@ -0,0 +1,183 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *                    > www.orxonox.net <
+ *
+ *
+ *   License notice:
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation; either version 2
+ *   of the License, or (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author:
+ *      Fabian 'x3n' Landau
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+// Inspired by boost::intrusive_ptr by Peter Dimov
+
+#ifndef _SmartPtr_H__
+#define _SmartPtr_H__
+
+#include "CorePrereqs.h"
+
+#include <ostream>
+
+namespace orxonox
+{
+    template <class T>
+    class SmartPtr
+    {
+        public:
+            inline SmartPtr() : pointer_(0)
+            {
+            }
+
+            inline SmartPtr(T* pointer) : pointer_(pointer)
+            {
+                if (this->pointer_)
+                    this->pointer_->incrementReferenceCount();
+            }
+
+            inline SmartPtr(const SmartPtr& other) : pointer_(other.pointer_)
+            {
+                if (this->pointer_)
+                    this->pointer_->incrementReferenceCount();
+            }
+
+            template <class O>
+            inline SmartPtr(const SmartPtr<O>& other) : pointer_(other.get())
+            {
+                if (this->pointer_)
+                    this->pointer_->incrementReferenceCount();
+            }
+
+            inline ~SmartPtr()
+            {
+                if (this->pointer_)
+                    this->pointer_->decrementReferenceCount();
+            }
+
+            inline const SmartPtr& operator=(T* pointer)
+            {
+                SmartPtr(pointer).swap(*this);
+                return *this;
+            }
+
+            inline const SmartPtr& operator=(const SmartPtr& other)
+            {
+                SmartPtr(other).swap(*this);
+                return *this;
+            }
+
+            template <class O>
+            inline const SmartPtr& operator=(const SmartPtr<O>& other)
+            {
+                SmartPtr(other).swap(*this);
+                return *this;
+            }
+
+            inline T* get() const
+            {
+                return this->pointer_;
+            }
+
+            inline operator T*() const
+            {std::cout << "(implizit)";
+                return this->pointer_;
+            }
+
+            inline T* operator->() const
+            {
+                return this->pointer_;
+            }
+
+            inline T& operator*() const
+            {
+                return *this->pointer_;
+            }
+
+            inline bool operator!() const
+            {
+                return (this->pointer_ == 0);
+            }
+
+            inline void swap(SmartPtr& other)
+            {
+                T* temp = this->pointer_;
+                this->pointer_ = other.pointer_;
+                other.pointer_ = temp;
+            }
+
+            inline void reset()
+            {
+                SmartPtr().swap(*this);
+            }
+
+        private:
+            T* pointer_;
+    };
+
+    template <class A, class B>
+    inline bool operator==(const SmartPtr<A>& a, const SmartPtr<B>& b)
+    {
+        return (a.get() == b.get());
+    }
+
+    template <class A, class B>
+    inline bool operator!=(const SmartPtr<A>& a, const SmartPtr<B>& b)
+    {
+        return (a.get() != b.get());
+    }
+
+    template <class T>
+    inline bool operator<(const SmartPtr<T>& a, const SmartPtr<T>& b)
+    {
+        return std::less<T*>()(a.get(), b.get());
+    }
+
+    template <class T>
+    void swap(SmartPtr<T>& a, SmartPtr<T>& b)
+    {
+        a.swap(b);
+    }
+
+    template <class T, class U>
+    SmartPtr<T> static_pointer_cast(const SmartPtr<U>& p)
+    {
+        return static_cast<T*>(p.get());
+    }
+
+    template <class T, class U>
+    SmartPtr<T> const_pointer_cast(const SmartPtr<U>& p)
+    {
+        return const_cast<T*>(p.get());
+    }
+
+    template <class T, class U>
+    SmartPtr<T> dynamic_pointer_cast(const SmartPtr<U>& p)
+    {
+        return dynamic_cast<T*>(p.get());
+    }
+
+    template <class T>
+    std::ostream& operator<<(std::ostream& os, const SmartPtr<T>& p)
+    {
+        os << p.get();
+        return os;
+    }
+}
+
+#endif /* _SmartPtr_H__ */
