Problem with static

I am getting coredump on linux (Red Hat 3.4.6-8).I am using gcc (GCC) 3.4.6 20060404 compiler. The problem is I have declared and used static map[i.e. STL] inside a function.This function is in say XYZ.so .Now at run time another host application is loading this XYZ.so, using it and then unloading it.Everything works fine,But when host application closes[i.e. exits] It is giving coredump.If we change static map to static vector then it works fine[no coredump while closing host application.].
My questions are,
1.Exactly when static variables in XYZ.so gets deallocated[After unloading XYZ.so or after exiting from main() of host apllication].

2.STL grows at runtime if needed and variables marked as static gets space in .obj at compile time i.e. fixed amount of space[not absolute memory location but the offset].Then how does compiler handles allocation and deallocation of variables of type static STL[i.e. static map,vector,..].

4.Also if static variables which are from XYZ.so are getting destructed after exiting main() of host application and XYZ.so is already unloaded then how does host application gets access of the destructors of static type which are declared in XYZ.so .