我有以下假设代码:
class User < ActiveRecord::Base
def oauth_consumer
@oauth_consumer ||= OauthConsumer.new(self)
end
end
class OauthConsumer
attr_reader :user, :access_token
def initialize(user)
@user = user
@access_token = OAuth::AccessToken.new(@user.token, @user.secret)
end
def get_posts_in_thread(thread_id)
response = access_token.get("/thread/#{thread_id}/user/#{user.id}")
JSON.parse(response.body)
end
end
user = User.new(:token => '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)是否处理了这种情况?