I've got a component manager that stores a reference to the component,
this component is created as a new instance or obtained thru a singleton.
and data type for it is boost::shared_ptr.
void Truck::Create()
{
SimObject::Create();
boost::shared_ptr<Arrivals> l_arrival = Arrivals::getInstance();
this->AddComponent(ComponentManager::getInstance()->AddComponent(l_arrival));
CMinMax<float> arrivalTime(10000.0f, 20000.0f);
this->FindCompoentByType<Arrivals>()->PostRequest(*this, arrivalTime.GetRandomNumber(), arrivalTime.GetRandomNumber());
When the component is first created, the strong count is 4,
1st from the getInstance itself
2nd from l_arrival
3rd from ComponentManager::getInstance()->AddComponent(l_arrival)
4th from this->AddComponent();
which is quite strongly referenced.
When the game exits, the game object dies,but the component stays alive,
the arrival component is basically an observable by the game object (the truck),
the truck dies, the observable has no observers to deliver messages to,
so the program crashes.
I like the idea of self-managed pointers, but it seems not applies here
Also the arrivals component has a threadpool in itself,
but the destructor of arrivals is too late to destruct, when it dies, all pending requests will be purged.
Any better idea for me?
Thanks
Jack