1
0
Fork 0

Fix leaking of dynamics/AI traffic

Use a weak-ref for ParkingAssignment to refer to its owning dynamics,
to avoid a circular dependency.
This commit is contained in:
James Turner 2020-08-11 18:30:44 +01:00
parent fa76d5b158
commit 3b5721d77e
2 changed files with 12 additions and 7 deletions

View file

@ -18,15 +18,14 @@
//
// $Id$
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <config.h>
#include <algorithm>
#include <string>
#include <vector>
#include <simgear/compiler.h>
#include <simgear/structure/SGWeakPtr.hxx>
#include <Environment/environment_mgr.hxx>
#include <Environment/environment.hxx>
@ -67,7 +66,10 @@ public:
~ParkingAssignmentPrivate()
{
dynamics->releaseParking(parking);
FGAirportDynamicsRef strongRef = dynamics.lock();
if (strongRef) {
strongRef->releaseParking(parking);
}
}
void release()
@ -84,7 +86,10 @@ public:
unsigned int refCount;
FGParkingRef parking;
FGAirportDynamicsRef dynamics;
// we don't want an owning ref here, otherwise we
// have a circular ownership from AirportDynamics -> us
SGWeakPtr<FGAirportDynamics> dynamics;
};
ParkingAssignment::ParkingAssignment() :

View file

@ -24,7 +24,7 @@
#include <set>
#include <simgear/structure/SGReferenced.hxx>
#include <simgear/structure/SGWeakReferenced.hxx>
#include <simgear/timing/timestamp.hxx>
#include <ATC/trafficcontrol.hxx>
@ -57,7 +57,7 @@ private:
ParkingAssignmentPrivate* _sharedData;
};
class FGAirportDynamics : public SGReferenced
class FGAirportDynamics : public SGWeakReferenced
{
private: