<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def in_memory(self, value):
 """Add or remove self from global memory. :param bool value: if True(False) ensure self is(is not) in memory. """


        self_class = self.__class__
        memory = Annotation.__ANNOTATIONS_IN_MEMORY__

        if value:
            annotations_memory = memory.setdefault(self_class, set())
            annotations_memory.add(self)

        else:
            if self_class in memory:
                annotations_memory = memory[self_class]
                while self in annotations_memory:
                    annotations_memory.remove(self)
                if not annotations_memory:
                    del memory[self_class]