Garbage collection of class instance variables in ruby -
if use method like
def self.get_service_client return @service_client if !@service_client.nil? @service_client = #initialize logic end
now @service_client
instance variable of class. how long in memory? can bank on not re-initialized long class in memory (i.e static variable)?
classes instances in ruby, too, when define class usual way, gets assigned constant, , constant referenced other constants, preventing collection. so, class in memory indefinitely. since class remain in memory, class instance variable too, class (which object instance) retains reference instance variables.
as aside, idiomatic way is:
def self.get_service_client @service_client ||= initialize_service_client end
Comments
Post a Comment