I have a class variable my_set which is a set, and into which I am adding strings:
MyClass.my_set.add(self.some_string_property)
My problem is that the instance of the class that runs the above may get garbage collected at any time, and when that happens I think I lose its some_string_property in my_set class variable.
In order to preserve some_string_property in my_set for each instance, I need to create a copy of it and store that copy into my_set. What is the right way to do so? I’ve tried the copy module but it doesn’t work on strings.
As long as you keep at least one reference to the string, it will not be garbage collected (and if you have no references left, then you have no way of accessing it anyway).