开发者

How to add a safe guarded to release the resource that should have been released explicitly by the client code

The user is supposed to call Player.close() to release some critical resources managed by the native code and kill several internal java threads created for the player object. However,the user failed to call it ,resulting in some resource leak. Adding a Finalize method won't work because the finalize won't be calle开发者_如何学运维d as the internal threads have not been killed...

How should we handle this situation?

EDIT:

I wiil look into the phantom reference. Besides, Shouldn't I terminate those aggregared thread so that player object become eligible for gc?


Make the internal threads hold only weak references to these things.

Perhaps consider learning about phantom references.


I still think that finalize is the only way to go, but you'll have to use some carefully placed weak reference(s) to give the GC a chance to kick in.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜