Skip to main content
1 of 2
Serban
  • 1.5k
  • 3
  • 9

You are running out of memory (heap space) not account space.

After you run the test, check the account (userInfoAddress in your test) with this command solana account %account_pubkey% (local validator must be running) and you will see that the account bytes returned have a lot of unused space (the padding 0s at the end).

        ...

77c0:   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00   ................
77d0:   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00   ................
77e0:   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00   ................
77f0:   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00   ................

What's likely happening is that Anchor is deserializing your account and thus putting the account in memory, the heap space is limited to 32k, and so when your account is more than or close to this it will create the error Error: memory allocation failed, out of memory.

To confirm this, get the account in JSON format, compress it, and calculate the size. You can do this with this command (local validator must be running):

anchor account solana_memory_issue.UserInfo %account_pubkey% | jq -c | wc -c

Convert the result to KB (divide by 1024) and you will get 32.99 KB.

Solutions to this depend on what you're trying to achieve. Maybe this answer to a similar question can help you.

PS: I greatly appreciate you adding the git link to reproduce this error.

Serban
  • 1.5k
  • 3
  • 9