PyNDN: Removing no longer necessary memory cleanup cheatings
diff --git a/PyNDN/Face.py b/PyNDN/Face.py
index d63550f..807fee7 100644
--- a/PyNDN/Face.py
+++ b/PyNDN/Face.py
@@ -27,19 +27,20 @@
 import functools
 import traceback
 
-deleteList = []
+class Face (object):
+    deleteList = []
 
-class Face (ns.ndnSIM.ndn.ApiFace):
     def __init__(self):
         self.nodeId = ns.core.Simulator.GetContext ()
         self.node = ns.network.NodeList.GetNode (self.nodeId)
-        super(Face, self).__init__ (self.node)
+        self._face = ns.ndnSIM.ndn.ApiFace (self.node)
+        # super(Face, self).__init__ (self.node)
 
     def connect (self):
         pass
 
     def disconnect (self):
-        self.Shutdown ()
+        self._face.Shutdown ()
 
     def defer_verification (self, deferVerification = True):
         pass
@@ -55,9 +56,7 @@
         interest.name = name
 
         converter = ExpressInterestConverter (onData, onTimeout)
-        deleteList.append (converter)
-
-        self.ExpressInterest (interest._interest, converter.handleOnData, converter.handleOnTimeout)
+        self._face.ExpressInterest (interest._interest, converter.handleOnData, converter.handleOnTimeout)
 
     def setInterestFilter (self, name, onInterest, flags = None):
         """
@@ -71,10 +70,7 @@
         else:
             raise TypeError ("Wrong type for 'name' parameter [%s]" % type (name))
 
-        converter = OnInterestConvert (onInterest)
-        deleteList.append (converter)
-
-        self.SetInterestFilter (name, converter)
+        self._face.SetInterestFilter (name, OnInterestConvert (onInterest))
 
     def clearInterestFilter (self, name):
         if isinstance (name, Name):
@@ -85,32 +81,25 @@
             raise TypeError ("Wrong type for 'name' parameter [%s]" % type (name))
 
         # @bug: memory leak, deleteList need to remove previosly set callback... but how?
-        self.ClearInterestFilter (name)
+        self._face.ClearInterestFilter (name)
 
     def get (self, name, template = None, timeoutms = 3000):
         raise NotImplementedError ("NS-3 simulation cannot have syncrhonous operations")
 
     def put (self, data):
         if isinstance (data, Data):
-            self.Put (data._data)
+            self._face.Put (data._data)
         elif isinstance (data, ns.ndnSIM.ndn.Data):
-            self.Put (data)
+            self._face.Put (data)
         else:
             raise TypeError ("Unsupported type to publish data [%s]" % type (data))
 
-def removeFromDeleteList (object):
-    try:
-        deleteList.remove (object)
-    except:
-        pass
-
 class ExpressInterestConverter:
     def __init__ (self, onData, onTimeout):
         self.onData = onData
         self.onTimeout = onTimeout
 
     def handleOnData (self, interest, data):
-        ns.core.Simulator.ScheduleNow (removeFromDeleteList, self)
         try:
             if self.onData:
                 return self.onData (Interest (interest=interest), Data (data = data))
@@ -118,7 +107,6 @@
             traceback.print_exc()
 
     def handleOnTimeout (self, interest):
-        ns.core.Simulator.ScheduleNow (removeFromDeleteList, self)
         try:
             if self.onTimeout:
                 self.onTimeout (Interest (interest=interest))
@@ -128,8 +116,8 @@
 class OnInterestConvert (object):
     def __init__ (self, onInterest):
         self.onInterest = onInterest
+
     def __call__ (self, name, interest):
-        ns.core.Simulator.ScheduleNow (removeFromDeleteList, self)
         try:
             if self.onInterest:
                 self.onInterest (Name (name = name), Interest (interest = interest))
diff --git a/model/ndn-face.cc b/model/ndn-face.cc
index 72b490e..293a6d7 100644
--- a/model/ndn-face.cc
+++ b/model/ndn-face.cc
@@ -75,7 +75,7 @@
   , m_metric (0)
   , m_flags (0)
 {
-  NS_LOG_FUNCTION (this);
+  NS_LOG_FUNCTION (this << node);
 
   NS_ASSERT_MSG (node != 0, "node cannot be NULL. Check the code");
 }
diff --git a/ndn.cxx/detail/pending-interests-container.h b/ndn.cxx/detail/pending-interests-container.h
index 78ab10d..673d33b 100644
--- a/ndn.cxx/detail/pending-interests-container.h
+++ b/ndn.cxx/detail/pending-interests-container.h
@@ -23,7 +23,12 @@
 public:
   PendingInterestEntry (Ptr<const Interest> interest)
     : m_interest (interest)
-  { }
+  {
+  }
+
+  virtual ~PendingInterestEntry ()
+  {
+  }
 
   void
   AddCallbacks (ApiFace::DataCallback onData, ApiFace::TimeoutCallback onTimeout)
diff --git a/ndn.cxx/ndn-api-face.cc b/ndn.cxx/ndn-api-face.cc
index 4d522fa..fd78763 100644
--- a/ndn.cxx/ndn-api-face.cc
+++ b/ndn.cxx/ndn-api-face.cc
@@ -51,7 +51,7 @@
     : m_rand (0, std::numeric_limits<uint32_t>::max ())
   {
   }
-  
+
   ns3::UniformVariable m_rand; // nonce generator
 
   PendingInterestContainer m_pendingInterests;
@@ -63,6 +63,8 @@
   : Face (node)
   , m_this (new ApiFacePriv ())
 {
+  NS_LOG_FUNCTION (this << boost::cref (*this));
+
   NS_ASSERT_MSG (GetNode ()->GetObject<L3Protocol> () != 0,
                  "NDN stack should be installed on the node " << GetNode ());
 
@@ -73,19 +75,21 @@
 
 ApiFace::~ApiFace ()
 {
+  NS_LOG_FUNCTION (this << boost::cref (*this));
+
   delete m_this;
 }
 
 void
 ApiFace::Shutdown ()
 {
-  NS_LOG_FUNCTION (this);
+  NS_LOG_FUNCTION (this << boost::cref (*this));
 
   if (!IsUp ())
     {
       return;
     }
-  
+
   this->SetUp (false);
 
   m_this->m_pendingInterests.clear ();
@@ -105,7 +109,7 @@
     {
       interest->SetNonce (m_this->m_rand.GetValue ());
     }
-  
+
   // Record the callback
   bool needToActuallyExpressInterest = false;
   PendingInterestContainer::iterator entry = m_this->m_pendingInterests.find_exact (interest->GetName ());
@@ -163,7 +167,7 @@
 ApiFace::Put (Ptr<Data> data)
 {
   NS_LOG_INFO (">> D " << data->GetName ());
-  
+
   Simulator::ScheduleNow (&Face::ReceiveData, this, data);
 }
 
@@ -178,7 +182,7 @@
   NS_LOG_FUNCTION (this << interest);
 
   NS_LOG_DEBUG ("<< I " << interest->GetName ());
-  
+
   if (!IsUp ())
     {
       return false;
@@ -222,7 +226,7 @@
       entry = m_this->m_pendingInterests.longest_prefix_match (data->GetName ());
     }
   m_this->m_pendingInterests.erase (entry);
-  
+
   return true;
 }