0

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.

1
  • 1
    How do you know the instance gets garbage collected? What are the actual symptoms? Commented Nov 26, 2012 at 22:52

1 Answer 1

5

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).

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.