# llSetMemoryLimit

*LSL function*

```lsl
integer integer llSetMemoryLimit(integer limit);
```

- `integer limit`: Integer memory limit in bytes to reserve (must be less than the 64KB maximum).

- Returns: `integer`
- Energy: 10

Requests that limit bytes are reserved for the script. Returns TRUE on success or FALSE on failure (has no effect in LSO).

Request **limit** bytes to be reserved for this script.

```lsl title="How to use" frame="terminal"
integer result = llSetMemoryLimit(0);
```

## Specification

This function's behavior is dependent upon the VM the script is using. [Mono](#mono) is the new VM, [LSO](#lso) is the old VM.

;Mono:Sets the memory limit for the script.

- The memory limit can be set up to 64k.
- The memory limit can not be set lower than the memory currently in use by the script.
- All new scripts start with a limit of 64k
- Mono scripts compiled before this function was introduced continue to use the 64k limit.
- A lower limit will effect the amount of memory reported in the viewer UI and by [llGetObjectDetails](/functions/llGetObjectDetails/).
- The memory limit is not the amount of real memory actually used by the script, just the upper limit on it.

;LSO:Has no effect on LSO scripts which will always use exactly 16k

## Caveats

;Mono:When ***n*** is too small, llSetMemoryLimit(***n***) is ignored and the memory limit is not changed

## Examples

<details open>
<summary>Example 1</summary>

```lsl collapse={1-13, 19-34}
// Memory-walkthrough by Daemonika Nightfire (daemonika.nightfire)

integer limit = 20000; // <- bytes

Test()
{
    llSetText("Limited Memory " + (string)llGetMemoryLimit() +
              "\nUsed Memory " + (string)llGetUsedMemory() +
              "\nFree Memory " + (string)llGetFreeMemory(),<1,1,1>,1);
}

default
{
    state_entry()
    {
        llSetMemoryLimit(limit);

        llScriptProfiler(PROFILE_SCRIPT_MEMORY);
        Test();
        llScriptProfiler(PROFILE_NONE);

        llSay(0,"This script used at most " + (string)llGetSPMaxMemory() + " bytes of memory during Test.");
    }
}

// Result:

// Floating Text:
// Limited Memory 20000
// Used Memory 4972
// Free Memory 15100

// Chat:
// [05:11] Object: This script used at most 4972 bytes of memory during Test.
```

</details>

## History

Date of Release [10/08/2011](https://wiki.secondlife.com/wiki/Release_Notes/Second_Life_Server/11#11-08-10-238207)

## See also

### Functions

- [llScriptProfiler](/functions/llScriptProfiler/)
- [llGetSPMaxMemory](/functions/llGetSPMaxMemory/)
- [llGetMemoryLimit](/functions/llGetMemoryLimit/)
- [llGetFreeMemory](/functions/llGetFreeMemory/)
- [llGetUsedMemory](/functions/llGetUsedMemory/)
- [llGetObjectDetails](/functions/llGetObjectDetails/)

---

*Source: [LlSetMemoryLimit](https://wiki.secondlife.com/wiki/LlSetMemoryLimit) on the Second Life Wiki. Content from the Second Life Wiki article LlSetMemoryLimit (revision 1194459, 2015-01-22), CC BY-SA 3.0.*

---

From lsl.dev: https://lsl.dev/functions/llSetMemoryLimit/
