I inherited an application where certain class is instantiated and passed back and forth multiple times. So I have about 20 private and public variables where
- Class instantiates:
myClass = MyClass() MyClassinstance is passed back and forth:self.myClass = someOtherClass.myClass- Sometimes variable is passed from class to class multiple times
- And a class may create a new instance or receive an instance from some other class in various cases
I want to fix this. But before changing anything I want to understand how many instances of that class I have, and which references point to the same instance.
What I do now: I am running the following statement in each method of MyClass:
print(Unmanaged.passUnretained(self).toOpaque())
and then additional prints in callers to identify who called that instance. This is quite tedious, but moreover it completely depends on my ability to cover all possible cases if this class usage at runtime, and it won't find nil references that classes may pass to each other (and which I need to know of)
So is there a better way? Or can this method be improved in some way?
Thanks in advance.