 void OnDisable() {
   Task *t = &ts.currentTask();
   unsigned int tid = t->getId();
-    
-  delete t;
+  toDelete.push(t);
+  tGarbageCollection.enableIfNot();
+
   Serial.print(millis()); Serial.print("\t");
-  Serial.print("Task N"); Serial.print(tid); Serial.print(F("\tfinished and destroyed.\tFree mem="));
+  Serial.print("Task N"); Serial.print(tid); Serial.println(F("\tfinished");
+  Serial.ptint("and destroyed.\tFree mem="));
   Serial.print(freeMemory());Serial.print(F("\tNo of tasks=")); Serial.println(--noOfTasks);
 }
 


  Serial.println(F("Dynamic Task Creation/Destruction Example"));
  Serial.println();
  Serial.print(F("Free mem="));
  Serial.print(freeMemory()); Serial.print(F("\tNo of tasks=")); Serial.println(noOfTasks);
  Serial.println();
}

void loop() {
  ts.execute();
}


/* Output on Arduino Uno:

void OnDisable();

int noOfTasks = 0;
QueueArray <(Task*)> toDelete;

void MainLoop() {
  Serial.print(millis()); Serial.print("\t");
