---
title: OutOfMemory
description: The luna reached its memory limit during the call, and the same call would fail again.
related:
  - /sdk/define-luna
  - /platform/limits
  - /errors
---

`OutOfMemory` means the luna reached its memory limit while it ran your call. The status is 500.

## Issue

A call fails with `OutOfMemory`. When the luna type sets a memory limit, the body carries it as `limitMib`.

```json
{"error": {"code": "OutOfMemory", "message": "<MESSAGE>", "limitMib": 512}}
```

## Cause

The handler needed more memory than the luna may use. Loading a large file whole, or every row of a big table at once, can do this.

Luna stops the call, and the call does not finish. Its writes are undone.

`OutOfMemory` differs from [`OutcomeUnknown`](/errors/outcome-unknown). With `OutcomeUnknown` nobody knows whether the call finished. With `OutOfMemory`, Luna knows it did not, and knows the same call would run out again.

## Solution

Do not retry the same call unchanged. It fails the same way.

- Use less memory in one call. Read rows a page at a time with `limit`, and read files in ranges.
- Raise the luna type's memory with [`limits`](/sdk/define-luna).

```ts luna/lunas/wallet.ts {6}
import { defineLuna, t } from "luna";

export const Wallet = defineLuna({
  name: "Wallet",
  key: { id: t.string() },
  limits: { memory: "2GB" },
  handlers: (h) => ({
    balance: h({ query: true }, () => 0),
  }),
});
```

A luna grows towards its `limits` as it needs to, and you pay for what it uses. [Limits](/platform/limits) covers the ceilings.
