Fix NSUndefinedKeyException prevention for garbage collection