dlopen打开的so库的引用计数


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 呢?


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值