eclipse-sumo / sumo

Eclipse SUMO is an open source, highly portable, microscopic and continuous traffic simulation package designed to handle large networks. It allows for intermodal simulation including pedestrians and comes with a large set of tools for scenario creation.
https://eclipse.dev/sumo
Eclipse Public License 2.0
2.49k stars 1.41k forks source link

memory cleanup in MSNet #7861

Open behrisch opened 3 years ago

behrisch commented 3 years ago

currently there is a crash in sumo\tests\sumo\extended\calibrator\swallow_downstream_jam_disabled because on deletion METriggeredCalibrator wants to remove its meandata instance from the segment which in turn wants to remove the reminder from the vehicles which are already deleted. Probably triggers should be cleaned up earlier just as detectors do in MSNet:clearAll or ~MSNet. Furthermore I don't see a reason why edges and lanes are cleared in clearAll while the meso segments are cleared in ~MSNet.

namdre commented 3 years ago

The call to MESegment::removeDetector is only used from the destructor of METriggeredCalibrator. Since we know that the vehicles are already destructed at this point we can simply omit the calls to MEVehicle::removeReminder (at least this is a workaround without memory leak).

Moving the call to MSCalibrator::cleanup(); ahead of delete myVehicleControl; strangely enough does not solve the crashing (when compiled with clang on linux).

The gcc build didn't even crash before your workaround.

behrisch commented 3 years ago

But sometimes calibrators are removed before the simulation ends aren't they? This would induce a crash then for the vehicle still has a dangling pointer.

namdre commented 3 years ago

No. As far as I can tell they are only deleted via the static cleanup method in the end.

namdre commented 2 years ago

Is this actually a regression ticket (Was the crash ever part of a release)? Do we need to do something else here?

behrisch commented 2 years ago

Yes, the crash has been present in 1.7.0. I still think there should be a way to safely remove a METriggeredCalibrator from a running simulation without causing a memory leak, even if it is not used yet. Also the cleanup order of lanes/edges vs. segments still needs a refactoring. But none of this is high priority.