# Lifetime and Concurrency

> Own editors and server controls correctly: ready and destroy, await using, sessions, bounded parallel requests, synchronous batches and recovery after errors.

- **Product:** TX Sheet Control
- **Section:** Documentation
- **Kind:** Topic
- **Path:** TX Sheet Control > Document Processing > Lifetime and Concurrency
- **752 words**
- **Web URL:** https://docs.textcontrol.com/tx-sheet-control/document-processing/lifetime/
- **LLMs URL:** https://docs.textcontrol.com/tx-sheet-control/document-processing/lifetime/llms.txt
- **LLMs-Full URL:** https://docs.textcontrol.com/tx-sheet-control/document-processing/lifetime/llms-full.txt

---

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:

1. Await [`ready`](https://docs.textcontrol.com/tx-sheet-control/reference/javascript-api/browser/spreadsheet/ready-property/llms-full.txt), then operate through its [`workbook`](https://docs.textcontrol.com/tx-sheet-control/reference/javascript-api/browser/spreadsheet/workbook-property/llms-full.txt).
2. When you remove the editor, remove your listeners and call [`destroy()`](https://docs.textcontrol.com/tx-sheet-control/reference/javascript-api/browser/spreadsheet/destroy-method/llms-full.txt).

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 using` for controls, which releases them through [`DisposeAsync`](https://docs.textcontrol.com/tx-sheet-control/reference/dotnet-api/txtextcontrol-txsheetcontrol-server/serversheetcontrol/disposeasync-method/llms-full.txt).
- **In Node.js**, use `try/finally` plus [`destroy()`](https://docs.textcontrol.com/tx-sheet-control/reference/javascript-api/nodejs/serversheetcontrol/destroy-method/llms-full.txt).

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`](https://docs.textcontrol.com/tx-sheet-control/reference/dotnet-api/txtextcontrol-txsheetcontrol-server/serversheetcontrol/createsession-method/llms-full.txt) 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 [`batch`](https://docs.textcontrol.com/tx-sheet-control/reference/javascript-api/browser/workbook/batch-method/llms-full.txt) group related changes.
- **In .NET**, collect batch commands synchronously through the typed batch API: [`BatchAsync`](https://docs.textcontrol.com/tx-sheet-control/reference/dotnet-api/txtextcontrol-txsheetcontrol-server/workbook/batchasync-method/llms-full.txt) with a [`WorkbookBatch`](https://docs.textcontrol.com/tx-sheet-control/reference/dotnet-api/txtextcontrol-txsheetcontrol-server/workbookbatch/llms-full.txt).

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](https://docs.textcontrol.com/tx-sheet-control/document-processing/performance/llms-full.txt): measure the throughput and latency of your concurrency settings.
- [Loading and Saving Workbooks](https://docs.textcontrol.com/tx-sheet-control/document-processing/load-save/llms-full.txt): reload a clean template and reacquire handles after loading.
- [Events and Cancellation](https://docs.textcontrol.com/tx-sheet-control/spreadsheet-editor/events/llms-full.txt): add and remove the listeners of an editor.
- [Batch Updates, Undo and Redo](https://docs.textcontrol.com/tx-sheet-control/spreadsheet-editor/undo-redo/llms-full.txt): group changes of the browser editor in a batch.

---

## Nearby

- **Previous:** [Backend Services](https://docs.textcontrol.com/tx-sheet-control/document-processing/backend-services/llms-full.txt)
- **Next:** [Measuring Performance](https://docs.textcontrol.com/tx-sheet-control/document-processing/performance/llms-full.txt)
