Lifetime and Concurrency
Each mutable document has an owner. Browser controls own their mounted UI, and backend controls own processing state. Handles identify objects inside one document generation and are invalid after a relevant deletion or replacement.
From ownership follow the rules for creating and disposing controls, for sharing them between jobs, for parallel requests and for grouping changes.
Own an Editor in the Browser
Create one editor per host. Then:
- Await
ready, then operate through itsworkbook. - When you remove the editor, remove your listeners and call
destroy().
Angular performs its component cleanup automatically.
Important
Handles After Loading. Do not keep using handles from a document that has been replaced by load.
Run Backend Jobs
Each platform has its own way to dispose a backend control:
- In .NET, use
await usingfor controls, which releases them throughDisposeAsync. - In Node.js, use
try/finallyplusdestroy().
Await all work before disposal. Unrelated jobs must not share mutable edits, and a reused control should reload a clean input or template for each unrelated request.
Sessions
Sessions, which CreateSession creates in .NET, may share capacity with their owner. A session is not automatically a separate parallel worker. For throughput tests, distinguish a pool of independent controls from many requests serialized through shared processing capacity.
Bound Concurrency
Limit parallel requests with a queue or semaphore, or with a worker pool. Include initialization, file size, formula count, PDF pages, font use and memory in capacity planning.
Increasing concurrency can improve throughput while it increases latency and memory. Measure both.
Group Changes in Batches
- In the browser, synchronous batches with
batchgroup related changes. - In .NET, collect batch commands synchronously through the typed batch API:
BatchAsyncwith aWorkbookBatch.
Fetch remote data before collecting mutations. Do not use asynchronous callbacks where the API requires synchronous collection.
Recover From Errors
Errors should leave a clearly defined document or result. If a request fails, discard or reload its state before reusing an owner for unrelated data.
Next Steps
- Measuring Performance: measure the throughput and latency of your concurrency settings.
- Loading and Saving Workbooks: reload a clean template and reacquire handles after loading.
- Events and Cancellation: add and remove the listeners of an editor.
- Batch Updates, Undo and Redo: group changes of the browser editor in a batch.