where memory is allocate outside of Java heap. gc

来源:互联网 发布:win10软件注册表 编辑:程序博客网 时间:2024/05/17 12:56
7down vote favorite
2
share [g+]share [fb] share [tw]

JDK provides abillity to allocate so-called direct ByteBuffers, where memory is allocate outside of Java heap. This can be beneficial since this memory is not touched by garbage collector, and as such does not contribute to GC overhead: this is a very useful for property for long-living things like caches.

However, there is one critical problem with existing implementation: underlying memory is only allocated asynchronously when the owning ByteBuffer is garbage-collected; there is no way to force early deallocation. This can be problematic since GC cycle itself is not influenced by handling of ByteBuffers, and given that ByteBuffers are likely to reside in Old Generation memory area, it is possible that GC is called hours after ByteBuffer is no longer in use.

But in theory it should be possible to use sun.misc.Unsafe methods (freeMemory, allocateMemory) directly: this is what JDK itself uses for allocating/deallocating native memory. Looking at code, one potential concern I see is possibility of double-freeing of memory -- so I would want to make sure that state would be properly cleaned.

Can anyone point me to code that does this? Ideally would want to use this instead of JNA.

NOTE: I saw this question which is sort of related.

Looks like the answers pointed out are good way to go: here is code example from Elastic Search that uses the idea. Thanks everyon!

原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 网上没有报名的怎么办? 上大学转户口怎么办 梅菜扣肉勾芡怎么办 有个精神病妈妈怎么办 妈得了精神病该怎么办 思维不正常的人怎么办 妈妈是个精神病怎么办 我老婆有精神病怎么办 在郑州怎么办完税证明 中专没考上大专怎么办 考研两次没考上怎么办 2018造价员取消后怎么办 造价员取消了投标怎么办 造价员考试取消后怎么办 只拿到结业证怎么办 本科只有结业证怎么办 健身后肌肉水肿怎么办 大腿面肌肉疼怎么办 跑步后大腿酸疼怎么办? 运动后大腿胀痛怎么办 尔雅课程没看完怎么办 国家课程校本化怎么办 上海买房限购怎么办 投资公司要求回购股份怎么办 超过应届生落户年龄怎么办 造价员章到期了怎么办 造价员继续教育过期了怎么办 sd卡存储不够怎么办? 进项税大于销项税怎么办 公司扣员工奖金怎么办 墙面大面积有霉怎么办 电脑总是断网怎么办 造价师资格证书丢了怎么办 行测做题速度太慢怎么办 普通话准考证丢了怎么办 信用卡还款逾期了怎么办 淮北建洗煤厂需要怎么办 建设工程不结算怎么办 考监理没有职称怎么办 公开招标两次招标失败怎么办 山东省植保员证怎么办