NSInvocation has a signature of the variable types of the method it represents, so it can retain the object ones without trying to retain plain integers.
Modern Obj-C uses blocks to make closures, which the compiler changes into structs holding all the variables referenced. It knows the types of these as well, so it writes code to retain any object types and releases them as it is released. They haven't got a cycle collector in the runtime, so programmers still make mistakes by accidentally making strong cyclic references.
Assuming the reference-counting GC, it's not hard, but you can still make mistakes.