Break retain cycles and fix memory leaks

Added __weak and __unsafe_unretained at the appropriate places to break all retain cycles. So finally the git repository gets dealloced when the window is closed.