ExtendScript never releases PathPoint objects: scripts slow down for the rest of the session
Hi all,
I make Illustrator scripts that clean up and compare artwork, and I've tracked down a slowdown that I think is a bug in ExtendScript's memory handling. I'd love to know if anyone has a workaround, or if Adobe can look at it.
What happens:
Every time a script reads a path point (pathItem.pathPoints[i], then .anchor or the handles), ExtendScript creates an object for that point and never frees it, even after the shape is deleted. As these pile up, every later script call in that engine gets slower, including in later runs. Only quitting Illustrator clears it.
What I measured ($.summary() object counts, 200 four-point rectangles):
- Reading every point: +800 PathPoint, +200 PathPoints, +800 Array. Expected so far.
- Then deleting the shapes, nulling every reference and running $.gc(): all 800 / 200 / 800 are still there.
- Duplicating the shapes, reading the copies, then app.undo() (the copies are gone): still there.
- Undoing the document back to empty, or closing it without saving: still there.
- Removing the points first (pathPoint.remove() or pathPoints.removeAll()), then the shapes: still there.
- Just taking a point (var p = pp[i], no property read) already creates the PathPoint object.
- Waiting (5 s, 30 s) and more $.gc() calls: no change.
- It happens in a CEP panel's engine and in Illustrator's main engine (File > Scripts) alike.
- toSource(), uneval() and String() on a path or its pathPoints don't return coordinates, so there's no way to read point positions without creating these objects.
run several times in a row:
#target illustrator
(function () {
var doc = app.documents.add();
// a fixed small job: 1,500 new rectangles, read each one's bounds, set a stroke, delete them
function job() {
var t0 = new Date().getTime(), layer = doc.layers.add(), refs = [], i;
for (i = 0; i < 1500; i++) { refs.push(layer.pathItems.rectangle(-(i % 50) * 3, Math.floor(i / 50) * 3, 2, 2)); }
for (i = 0; i < refs.length; i++) { var b = refs[i].geometricBounds; refs[i].strokeWidth = 0.5; }
layer.remove();
return new Date().getTime() - t0;
}
// n new rectangles, read every anchor, delete them
function readPoints(n) {
var layer = doc.layers.add();
for (var i = 0; i < n; i++) {
var pp = layer.pathItems.rectangle(-(i % 50) * 3, Math.floor(i / 50) * 3, 2, 2).pathPoints;
for (var k = 0; k < pp.length; k++) { var a = pp[k].anchor; }
}
layer.remove();
}
var before = job();
readPoints(6000); // 24,000 points read; the shapes are deleted again
$.gc();
var after = job();
alert('The same job: ' + before + ' ms before, ' + after + ' ms after reading 24,000 points.\n' +
'Run this script a few more times: it keeps getting slower until Illustrator is restarted.');
})();
My results (Illustrator 2026, Windows, freshly started): the small job took about 100 ms on the first run. Running the same script again and again, it climbed every run: about 480 ms, then 630 ms by the fourth run. The shapes are deleted every time, so nothing is left in the documents. Only restarting Illustrator brings it back to 100 ms.
This hits any script that reads a lot of path points (cleaning up, comparing or measuring artwork), and everything after it in the same session.
Questions:
1. Is this a known issue, and is there a way to release these point objects without restarting Illustrator?
2. Is there any way to read a path's points in bulk (as plain numbers) without creating a PathPoint object per point?
Thanks!
