LISP slows down as progresses

Hi,


I have written a LISP routinne to work on a file with 1300 layers.  It steps through the layers doing things like join and hatch.  It starts off reasonably quickly but grinds to a halt.  Before moving to the next layer I implement a delete and purge on the layer but memory is being taken up somewhere.  Undo history or similar, Does anyone have any suggestions to speed things up?