Most commonly, in drama, the quick-witted invention of dialogue to cover a performer's memory lapse would be an example of an ad-lib. Or, a director might encourage performers to ad-lib in a particular show. (The term ad-lib usually refers to the interpolation of unscripted material in an otherwise scripted performance. When the entire performance is grounded in spontaneous creation, the process is usually called improvisation).
Live performers such as television talk-show hosts sometimes enhance their reputation for wit by the delivery of material that sounds ad-libbed but is actually scripted, and may employ ad-lib writers to prepare such material.
In music, the composer may direct a certain part to be played ad lib if the part is extraordinarily difficult—but if the musician is playing ad lib, the feel of the passage and the overall effect will come across to the listener, perhaps more faithfully than if the notes had been precise.
See also