Weak refrences to an object can be collected if no strong refrences remain, but we can disable it!
Lists and dictionaries cannot be weak refrenced, but this can:

class Dict(dict):
    pass
class List(list):
    pass

If your holding a large dictionary, you might want to split up over diffrent variables, like this:

import weakref,gc
gc.disable() #no garbage collection!
d = weakref.WeakValueDictionary() #if your values are large(otherwise use WeakKeyDictionary)
#do what ever#

Want group things held together (no order) that also have regular value names?(Deleted when no strong refrences)
Just use weakref.WeakSet!

Also, try to wrap this around it:

try:
    #your code
except MemoryError:
    gc.collect()
    del gc.garbage[:]

So if you run out of memory, you could run a garbage collection (and delete the unreachable grabage)and hope for the best.

I'm not sure I understand which problem you are addressing with this code ...