(Today's questions are very CPython-specific, but that hasn't stopped me before. :)
I spent some time today looking for the source of a bug that caused my program to leak memory. A C module ultimately proved to be at fault; before figuring that out, though, I suspected that something was hanging on to data read over a socket longer than it should. I decided to check this by summing the length of all string objects:
>>> import gc >>> sum([len(o) for o in gc.get_objects() if isinstance(o, str)]) 0
No string objects? Can't be. Let's try this:
>>> a = 'asdfjkl;' >>> len([o for o in gc.get_objects() if isinstance(o, str)]) 0
- (Easy) Why don't string objects show up for get_objects()?
- (Harder) How can you get a list of live string objects in the interpreter?