dlopen打开的so库的引用计数

来源:互联网 发布:awesome note for mac 编辑:程序博客网 时间:2024/06/18 08:31


http://stackoverflow.com/questions/4732018/what-happens-to-the-global-variables-in-shared-library-when-dlclose-is-called-on?rq=1

If dlclose reduces the reference count to zero and the library is actually unloaded, any future reloading of the library should reset all variables with static storage duration in the library to their original values.

However, if the library was opened more than once, all but the final call to dlclose will just decrement the reference count. Sometimes it may not be obvious whether a library was opened more than once, since it might have gotten loaded as a dependency of some other library without you knowing, unless it's a module local to your program, so it's probably not a good idea to rely on this "reset" behavior.

Employed Russian added:

Even if the library is dlopen()ed and dlclose()d exactly once, and is not a dependency of something else, the act of referencing symbols from it (via dlsym()) will also increment the reference count (and make the library not unloadable); at least on Linux.

I have no idea if this information is accurate or not. In the future, please post new information as a comment or a new answer, not an edit to other people's answers. If you just edit someone else's answers, you make them take responsibility for the correctness of your answer, which they may not want.

 是这样的吗? dlsym()也会增加dl的引用计数? 那什么时候引用计数会变为 0 呢?


原创粉丝点击