The UndoManager.contentRemoved() method is called by the JEditBuffer.remove() method and is supplied with a new string object for every call. In large search&replace-all scenarios this can quickly fill up memory as a reference is hold by the created CompoundEdit object, so these objects cannot get garbage collected. Use the KillRing, that is called anyway, to check for the existence of an equal String object. Sadly this doesn't work for whitespace replaces as the KillRing doesn't seem to store these.
For the test file in patch 3527797 (file: jedit-slow-search-replace-small.txt.zip) and a search-and-replace-all from "," to ", " this saves about 72MB of String objects for this simple search&replace-all case.