Skip to content

redis内存回收 #872

Open
Open

Description

@fourierr

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

Activity

  1. LiWenGu commented on Jul 30, 2020

    @LiWenGu
    Contributor

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

  2. added
    discuss
    help wanted
    on Aug 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    discusshelp wanted

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions