Hi,
I'm writing the code for a routing protocol, and I'm having one issue when running simulations. The code worked just fine until I added a functionality to turn nodes on and off. It causes a memory leak (or something like that), the use of memory grows a lot during the simulations (the simulations have up to 10,000 nodes).
The code that I use to turn nodes on and off is:
void
RoutingProtocol::Enable ()
{
NS_LOG_FUNCTION (this);
NS_LOG_DEBUG ("Turning on WifiNetDevice...");
Ptr<Node> node = m_ipv4->GetObject<Node> ();
Ptr<NetDevice> device = node->GetDevice (0);
Ptr<WifiNetDevice> wifi_device = DynamicCast<WifiNetDevice> (device);
Ptr<WifiPhy> wifi_phy = wifi_device->GetPhy ();
wifi_phy->ResumeFromOff ();
wifi_phy = 0;
wifi_device = 0;
device = 0;
node = 0;
NS_LOG_DEBUG ("WifiNetDevice successfully turned on.");
}
void
RoutingProtocol::Disable ()
{
NS_LOG_FUNCTION (this);
NS_LOG_DEBUG ("Turning off WifiNetDevice...");
Ptr<Node> node = m_ipv4->GetObject<Node> ();
Ptr<NetDevice> device = node->GetDevice (0);
Ptr<WifiNetDevice> wifi_device = DynamicCast<WifiNetDevice> (device);
Ptr<WifiPhy> wifi_phy = wifi_device->GetPhy ();
wifi_phy->SetOffMode ();
wifi_phy = 0;
wifi_device = 0;
device = 0;
node = 0;
NS_LOG_DEBUG ("WifiNetDevice successfully turned off.");
}
RoutingProtocol is the class that inherits the Ipv4RoutingProtocol class.
Before the addition of these two functions (
RoutingProtocol::Enable and
RoutingProtocol::Disable) there were no problems (memory usage remained very stable). Furthermore, even with these functions, but with the calls to
ResumeFromOff() and
SetOffMode() commented out, the memory leak/high memory usage does not occur.
Something inside ResumeFromOff() and SetOffMode() causes this issue. I read the code of these two functions but I don't understand why or what causes the memory leak/high memory usage.
Does anyone know what may fix this issue I'm having?
Thanks! :)
PS. Currently, I'm using NS-3 version 3.29.