> For the complete documentation index, see [llms.txt](https://sogni.gitbook.io/sogni-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://sogni.gitbook.io/sogni-docs/sogni-studio/advanced/processing/on-device/optimizing-memory.md).

# Optimizing Memory

Within the processing field in the Advanced tab, you can toggle Optimize Memory Usage on and off.

<div align="left"><figure><img src="/files/KxG03N6v1IM6CqHdLbaQ" alt="" width="431"><figcaption></figcaption></figure></div>

When this option is enabled, Sogni loads and unloads models just-in-time to prevent memory shortages, which can increase latency by approximately 2 seconds in exchange for reducing memory usage. The Stable Diffusion pipeline will lazily load TextEncoder, Unet, Decoder, and SafetyChecker when needed and aggressively unload their resources afterward.

Optimizing memory usage can be advantageous when running resource-intensive models on systems with less than 32GB of RAM, or if the generation process is causing your Mac to run slowly.

This option is automatically enabled if your Mac has less than 16GB of RAM, and it is not recommended to disable it.

***

**Need help? Ask in our Discord!**

For any questions regarding the use of Sogni, tips, suggestions, bugs, sharing art, discussing AI and life, or simply hanging out... Join our Discord community!\
\
[Join Sogni Discord](https://discord.com/invite/2JjzA2zrrc) ✨<br>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://sogni.gitbook.io/sogni-docs/sogni-studio/advanced/processing/on-device/optimizing-memory.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
