We are all familiar with marking and cleaning the ball on the putting green which the Rules permit and there are only a few situations when the ball cannot be cleaned when lifted. One is when you lift your ball so that it does not interfere with or assist another ball in play. Before you lift it, mark its position and make sure you don’t clean it while holding it. The Rules do not say that it must be held between thumb and index finger just that it must not be cleaned! To avoid any argument you could leave it on the ground but remember to replace it correctly when it is your turn to play. If by chance you do unintentionally clean it while holding it, it is a one stroke penalty only in both stroke play and match play.
If you lift the ball to identify it you may only clean it to the extent necessary to make sure that it is yours. Similarly if you lift it to see if it is cracked or unfit for use.
In all other situations you may clean a ball when you lift it and before you drop it, for example when dropping under penalty, when taking free relief or when winter rules are in place before you prefer the lie or drop from where it has embedded.