Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

redis内存回收 #872

Open
fourierr opened this issue Jul 28, 2020 · 1 comment
Open

redis内存回收 #872

fourierr opened this issue Jul 28, 2020 · 1 comment

Comments

@fourierr
Copy link

@fourierr fourierr commented Jul 28, 2020

如redis-内存回收和内存共享部分所描述: 因为c语言不具备自动内存回收功能,当将redisObject对象作为数据库的键或值而不是作为参数存储时其生命周期是非常长的,为了解决这个问题,Redis自己构建了一个内存回收机制,通过redisobject结构中的refcount实现.这个属性会随着对象的使用状态而不断变化。
1、创建一个新对象,属性初始化为1
2、对象被一个新程序使用,属性refcount加1
3、对象不再被一个程序使用,属性refcount减1
4、当对象的引用计数值变为0时,对象所占用的内存就会被释放
其中不太理解如何进行这种基于refcount的引用计数回收,对于过期的数据进行的是定期删除和惰性删除,当内存要溢出时进行的是淘汰机制(noeviction、volatile-lru等),但是文中所描述的这种引用计数的回收方式在何时进行呢?

@LiWenGu
Copy link
Contributor

@LiWenGu LiWenGu commented Jul 30, 2020

这个案例中,你可以理解为:定时删除和惰性删除触发的时候,删除的是 refcount = 0 的对象

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.