Classes are also instances in Ruby, but when you define a class in the usual way, it is assigned to a constant, and this constant refers to other constants, preventing its collection. Thus, the class will be in memory indefinitely. Since the class will remain in memory, the class instance variable will also be, since the class (which is an instance of the object) maintains a reference to its instance variables.
Aside, the idiomatic way to do this is:
def self.get_service_client @service_client ||= initialize_service_client end
source share