Why is this looping indefinitely ? Does not go to exception.
Why should it?
I haven't verified that, but I guess MarkupByClass eventually returns nil, and RemoveMarkup does nothing.
If so, you can check yourself if the value is nil.
You are aware, that once you done that, you must ensure not to call SynEdit.SetHighlightSearch (or related).
They have a pointer (dangling pointer, after you removed it) to the markup.