•A feature source: Holds the data definition and related settings, including the schema, fields, and popup configuration.
•Individual features: Created for each graphic to hold its attributes and geometry.
Because the feature source and the individual features are separate objects, destroying one does not automatically destroy the other.
•Process in manageable batches: In production workflows, query or produce smaller batches rather than holding an entire input dataset in memory at once. Process each real batch only once. (Note: Stress-test sample workflows often repeat query references to simulate large datasets, meaning their totals do not reflect unique records).
•Keep only what downstream steps need: If later steps only require a count, summary, or specific attribute values, extract that data and destroy the feature objects immediately. Do not add result batches to persistent collections in count-only workflows.
•Clear completed input arrays: Once the workflow finishes using a query result, clear or replace the variable holding that array (for example, by setting it to []). If a later step still needs the original features, retain them until that step finishes.
•Follow the strict cleanup sequence: For every batch, execute cleanup steps in this exact order:
1.Complete all processing: Finish every step that relies on the batch's features.
2.Destroy the features: Call destroy() on each converted feature to release its geometry, attributes, and event watches.
3.Destroy the feature source: Call destroy() on the batch's shared feature source once per batch. Destroying the source is critical because it retains watches, schemas, and configuration resources.
4.Clear variable references: Remove all references to the processed batch from workflow variables and collections.
Calling destroy() releases underlying resources immediately and makes the object unusable in subsequent steps. Never destroy features or sources while a downstream step still needs to query, display, or read them.
javascript
// Cap the batch size at 1,000 features
$indexs1.result = {
start: 0,
end: Math.min($maxPerSet1.result, $set.result.length)
};
$subset1.result = $set.result.slice($indexs1.result.start, $indexs1.result.end);
javascript
// Destroy each converted feature
$runOperation3.result.forEach(feature => feature.destroy());
// Destroy the shared batch source once (if results exist)
$runOperation3.result.length > 0 && $runOperation3.result.source
? $runOperation3.result.source.destroy()
: undefined;
javascript
$set.result.splice(0, $indexs1.result.end);
This step removes the processed entries from the working collection, but in the attached sample $query_renewables.features still holds the original query result array. Because $set.result was populated with references to those same query features, splicing $set.result does not release the original query features.
If the workflow has finished with the query result, clear or replace the variable that owns that array as well; for example, set the query result variable to an empty array if the workflow design permits. If a later step still needs those original features, keep them until that step has finished. For production workflows, prefer querying or producing manageable batches so the workflow does not need to retain the full input result while processing it.
The order is important:
- Finish using the converted batch.
- Count or save the needed result.
- Destroy the returned features and their temporary source.
- Remove processed input features from the collection that held them.
The sample is a stress-test workflow. It repeats query feature references to build a large collection, so its total is not a count of unique records. In a production workflow, process each real batch once.
If a downstream step must display, query, or otherwise use converted features, do not destroy the batch immediately. Keep both the features and their temporary source reachable until their final use, then clean them up together.
Even when retaining features for later steps, avoid holding every batch until the very end of a large workflow. Whenever possible, process and release each batch immediately after its own final use to avoid high peak memory.
javascript
// 1. Destroy each converted feature after its final use
$graphicsSet.result.forEach(feature => feature.destroy());
// 2. Destroy each distinct batch source once (do not destroy per feature)
$batchSources.result.forEach(source => source.destroy());
// 3. Clear the references held by the workflow collections
$graphicsSet.result.length = 0;
$batchSources.result.length = 0;
•Delayed memory monitor drops: Calling destroy() does not guarantee an immediate drop in your browser's task manager or memory profiler.
•Browser-managed garbage collection: JavaScript garbage collection runs on the browser's own schedule, and the browser may keep freed memory reserved for future reuse.