这段代码是否在Ruby中创建了循环内存引用?
我有以下假设代码:
class User 'token', :secret => 'secret') # I want to get the user's posts in thread #12345. user.oauth_consumer.get_posts_in_thread(12345)
我想知道这是否创建了一个循环内存引用,其中user
有oauth_consumer
的引用,而oauth_consumer
有一个对user
的引用,因此无法进行垃圾回收?
或者底层GC实现(REE 1.8.7)是否处理这种情况?
以下讨论表明Ruby的GC appraoch(标记和扫描)应对循环引用: