In my c++ project under windows, I've seen a CRASH!
Why will ~weak_ptr() crash in a dll?
Here is my project:
App.exe
Parent.dll
Child1.dll
There is a codes:
Parent.dll
void setSomeInfosToChild() {
child1 = loadLibrary("child1");
std::share_ptr<xx> info = std::make_shared<xx>();
child1.setInfo(info);
}
Child1.dll
void setInfo(std::weak_ptr<xx> info) {
this->m_info = info;
}
std::weak_ptr<xx> m_info
when m_info was doing destructing method, it crashed!
Here is what I've done so far:
Used VMMAP to see that, when Child1.dll was releasing it's resources, Parent.dll had been released, App.exe can no longer find Parent.dll!
Used Dumpbin.exe to see that, Parent.dll's dependencies had Child1.dll, while App.exe had NOT Parent.dll!
These had driven me to learn about 'Implicit Linking' and 'Explicit Linking' of dll. For details, you could do research yourserf. There is not enough time for me to write here :<
Above, you should have known that the Parent.dll was linked explicitly. But I haven't studied why Parent.dll was released before Child1.dll yet. Therefore, I tried linking Parent.dll implicitly. And it didn't crash any more.
The study will be continued... Hope that I will have enough time:)