macOS: App icon remaining in Dock even after closing app
Every time I connect my iPhone to my MacBook, the system launches iTunes which I don't use. After I close it, the icon remains in the Dock and I have to right click and remove it. I don't move the icon in the Dock and I don't touch the Dock at all in this process.
Note that I am very aware that applications may be on the dock unless they are fully closed. In this case, not only is the app closed but the Activity Monitor does not list the process running.
Staying in the Dock also happens with other applications after I start them, but not all applications. Skype opened itself on reboot and after closing that application, it remained in the Dock. I also verified it is not listed in Activity Monitor. I removed the option to launch Skype on start and that one won't spin up each time, thankfully. But if I launch Skype manually it has the same behavior, it will place itself persistently into the Dock after it is closed.
How does an application put itself in the Dock? Is there a way to turn that off? Is it a setting?
Solution 1:
macOS Mojave introduced a feature to show recently launched app's icons in the Dock, even after quitting the app. To a new user of macOS, even if they have been using earlier releases of macOS for a while, this may give an impression that either the app is still running, or the icon got persistently added to the Dock. To disable Dock from displaying recently launched app icons in the Dock, go to System Preferences app → Dock and uncheck Show recent applications in Dock. This setting is enabled by default in macOS Mojave.
While this was not the reason in this particular case, some other reasons this may happen are discussed below:
A macOS app is generally (well in majority of cases) programmed to show it's icon in the Dock when it's launched. (There's an exception to this general rule, an app can be programmed to run and show their icon only in the Menu bar).
Unlike other desktop operating systems, a macOS app generally doesn't quit when you click on the close button (shown in red below):
Clicking the close button generally close the app window and doesn't necessarily quit the app. The app keeps running. (I said generally, because some app are programmed to quit when the close button is clicked).
The way to quit an app completely is either to use Menu bar command App Name → Quit App Name, or to use the universal keyboard shortcut Command + Q. This will always quit the app and remove it's icon from the Dock (if the icon wasn't present in the Dock before app was launched, and you haven't enabled Keep in Dock from the app's Dock icon's context menu).
If an app icon is not present in the Dock before it is launched, it doesn't automatically gets added to the Dock when the app is run.
Another possible scenario where the app icon remains in the Dock happens when you have manually rearrange it in the Dock. Once an app icon is moved to a new location in Dock, the Keep in Dock option in the Dock icon's context menu gets checked. This is by design.
As far as automatic launch of iTunes is concerned when an iPhone (or any other iOS device) is connected to your Mac, you can turn this off. Launch iTunes and open iTunes preferences by using Menu bar command iTunes → Preferences... or using keyboard shortcut Command + ,, go to Devices tab and check Prevent iPods, iPhones and iPads from syncing automatically.