Index: orxonox/trunk/src/util/garbage_collector.cc
===================================================================
--- orxonox/trunk/src/util/garbage_collector.cc	(revision 4938)
+++ orxonox/trunk/src/util/garbage_collector.cc	(revision 4941)
@@ -37,4 +37,7 @@
    this->setClassID(CL_GARBAGE_COLLECTOR, "GarbageCollector");
    this->setName("GarbageCollector");
+
+   this->collectedObjects = NULL;
+   this->unusedContainers = NULL;
 
    this->time = 0;
@@ -81,4 +84,28 @@
 
 /**
+ * collect an Object, that should be scheduled for clearing.
+ * @param object the Object to schedule.
+ */
+void GarbageCollector::collect(BaseObject* object)
+{
+  printf("TEST\n");
+  State::getWorldEntityList()->remove(dynamic_cast<WorldEntity*>(object));
+  FastObjectMember* tmpC;
+  if (unlikely(this->unusedContainers == NULL))
+  {
+    tmpC = new FastObjectMember;
+  }
+  else
+  {
+    tmpC = this->unusedContainers;
+    this->unusedContainers = this->unusedContainers->next;
+  }
+
+  tmpC->next = this->collectedObjects;
+  tmpC->objectPointer = object;
+  this->collectedObjects = tmpC;
+}
+
+/**
  *  this ticks the GarbageCollector to give it the time pulse
  * @param time: the time passed since last tick
@@ -92,46 +119,74 @@
 
 
+void GarbageCollector::update()
+{
+  if (this->time < this->delay)
+  {
+    return;
+  }
+  if (this->collectedObjects == NULL)
+    return;
+  else
+  {
+    FastObjectMember* tmpC = this->collectedObjects;
+    FastObjectMember* moveC;
+    while (tmpC != NULL)
+    {
+      WorldEntity* entity = dynamic_cast<WorldEntity*>(tmpC->objectPointer);
+      //State::getWorldEntityList()->remove(entity);
+      entity->remove();
+      FastFactory::kill(entity, true);
+
+      moveC = tmpC->next;
+      tmpC->next = this->unusedContainers;
+      this->unusedContainers = tmpC;
+      tmpC = moveC;
+    }
+    this->collectedObjects = NULL;
+  }
+}
+
 /**
  *  this updated the gargabe collection, if the time is ready
 */
-void GarbageCollector::update()
-{
-  if( this->time < this->delay)
-    return;
-  /* garbage collect */
-  PRINTF(3)("=============================\n");
-  PRINTF(3)("Processing Garbage Collection\n");
-  PRINTF(3)("=============================\n");
-  int counter = 0;
-
-  tList<WorldEntity>* list = State::getWorldEntityList();
-
-  tIterator<WorldEntity>* iterator = list->getIterator();
-  WorldEntity* entity = iterator->nextElement();
-  while( entity != NULL)
-    {
-      if( entity->isFinalized())
-        {
-          PRINTF(4)("= finalizing object\n");
-          ++counter;
-
-          /* first remove out of entity list */
-          list->remove(entity);
-          /* second remove out of pnode tree */
-          entity->remove();
-          /* then finaly delete reference */
-          //delete entity;
-          //FastFactory::kill();
-          //ObjectManager::getInstance()->addToDeadList(entity->getClassID() & CL_MASK_LOWLEVEL_CLASS, entity);
-        }
-      entity = iterator->nextElement();
-    }
-
-  PRINTF(3)("= collected %i unused objects\n", counter);
-  PRINTF(3)("=============================\n");
-
-  //ObjectManager::getInstance()->debug();
-
-  /* reset time to count again up to this->delay */
-  this->time = 0;
-}
+// void GarbageCollector::update()
+// {
+//   if( this->time < this->delay)
+//     return;
+//   /* garbage collect */
+//   PRINTF(3)("=============================\n");
+//   PRINTF(3)("Processing Garbage Collection\n");
+//   PRINTF(3)("=============================\n");
+//   int counter = 0;
+//
+//   tList<WorldEntity>* list = State::getWorldEntityList();
+//
+//   tIterator<WorldEntity>* iterator = list->getIterator();
+//   WorldEntity* entity = iterator->nextElement();
+//   while( entity != NULL)
+//     {
+//       if( entity->isFinalized())
+//         {
+//           PRINTF(4)("= finalizing object\n");
+//           ++counter;
+//
+//           /* first remove out of entity list */
+//           list->remove(entity);
+//           /* second remove out of pnode tree */
+//           entity->remove();
+//           /* then finaly delete reference */
+//           //delete entity;
+//           //FastFactory::kill();
+//           //ObjectManager::getInstance()->addToDeadList(entity->getClassID() & CL_MASK_LOWLEVEL_CLASS, entity);
+//         }
+//       entity = iterator->nextElement();
+//     }
+//
+//   PRINTF(3)("= collected %i unused objects\n", counter);
+//   PRINTF(3)("=============================\n");
+//
+//   //ObjectManager::getInstance()->debug();
+//
+//   /* reset time to count again up to this->delay */
+//   this->time = 0;
+// }
