The rules here are nothing special ... you need to retain an object until you
no longer want to use it.
In this case you say you want to keep the connection until the program ends (so
you can get messages from other apps), so the correct behavior is to keep the
object retained until the program ends ... which is what your code does.
The compiler is warning you because it sees the variable go out of scope (at
which point it becomes impossible for you to release it), but that's harmless
because you never want to release it.
That being said, the compiler is warning you about a bad practice ... you
really should use a global variable or instance variable.
Not only will doing that avoid the compiler warning, it will also allow you to
release the connection explicitly on or before program termination.
I like to invalidate and release connections immediately before shutdown, in
order to ensure that messages from other apps don't arrive while in the process
of shutting down. If your app has a complicated clean-up process when it shuts
down, an incoming message at that point could mess things up, so it's simpler
to stop accepting messages and then do other cleanup.