Please enable JavaScript to view this site.

Navigation: Advanced

Memory Management

Prev Top Next More

Managing Feature Memory in Workflows

Workflows that convert large numbers of graphics into features can consume significant browser memory. If batches remain in memory across loop iterations or consecutive workflow runs, peak memory usage climbs, which can lead to browser slowdowns or crashes.

This topic explains which objects stay in memory during batch processing and how to release resources as soon as a batch is no longer needed.

How "results.from-graphics" Uses Memory

Each call to results.from-graphics creates two separate types of objects:

•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.

As long as a workflow variable, collection, or downstream step references a feature or source, the browser must keep it in memory. While JavaScript's garbage collector eventually frees unreferenced objects, cleanup does not happen immediately. Explicitly releasing resources ensures memory is freed promptly between batches and workflow runs.

Best Practices for Batch Memory Management

Follow these core principles when designing workflows that process large feature sets:

•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.

Pattern 1: Process and Count in Batches (Discard Features Immediately)

Use this pattern when your workflow needs summary data (such as a total feature count) but does not need to retain the converted features for later steps. Adapt the variable names below to match your workflow.

1. Retrieve the Query Results
The Query Layer step stores its output in $query_renewables.features. (In the sample stress-test workflow, these features are added to $set.result multiple times to build a large collection).

2. Slice a Single Batch
Set the batch size to either 1,000 or the number of remaining features (whichever is smaller), then extract that slice:

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);

3. Convert and Count the Batch
Call results.from-graphics using $subset1.result and the map extension. This generates converted features and a temporary feature source for that specific call. Add the resulting array length to $featureCount.result.

4. Destroy the Converted Features and Source
After recording the count, destroy every returned feature, then destroy the shared source once. Always verify that the result array is non-empty before reading .source from the first feature:

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;

5. Remove Processed Input References
Remove the completed batch from $set.result before starting the next loop iteration:

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.

 

Pattern 2: Retain Converted Features for Downstream Steps

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.

Tracking and Destroying Batch Sources

Each from-graphics call shares one temporary source across all features returned by that call. When a from-graphics call completes and returns a non-empty result, record its source (for example, by reading .source from the first returned feature and storing it in a tracking array like $batchSources.result ). This allows you to destroy each distinct batch source once rather than once per feature.

Cleanup Script Example

Assuming $graphicsSet.result collects your converted features and $batchSources.result tracks each distinct batch source, run the following cleanup after the final step that uses the features:

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;

What to Expect After Calling destroy()

Calling destroy() triggers explicit resource cleanup immediately, reducing how much memory carries into the next batch or workflow run. However, keep these browser behaviors in mind:

•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.

The goal of explicit cleanup is to release completed batches promptly so consecutive runs do not overlap with leftover resources from earlier runs.

 

 

© 2026 VertiGIS North America Ltd. All Rights Reserved. | Privacy Center | Imprint
Documentation Version 5.54 (9ae53d34)