fix bug in finalizing weak keys and values in dictionaries