# App starts using 384 GB of virtual memory

**URL:** <https://forum.xojo.com/t/app-starts-using-384-gb-of-virtual-memory/80352>\
**Category:** macOS\
**Created:** [May 18, 2024, 5:39am UTC](https://forum.xojo.com/t/app-starts-using-384-gb-of-virtual-memory/80352 "2024-05-18T05:39:12Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![Beatrix\_Willius](https://forum.xojo.com/user_avatar/forum.xojo.com/beatrix_willius/32/282_2.png) [@Beatrix\_Willius](https://forum.xojo.com/u/Beatrix_Willius)\
**Post date:** [May 18, 2024, 5:39am UTC](https://forum.xojo.com/t/app-starts-using-384-gb-of-virtual-memory/80352/1 "2024-05-18T05:39:12Z")

</div>

I have a really weird problem with one user. He can’t connect to an SQLite database. I traced this back to a pragma where I reserve memory for the database. Then I noticed something odd in the startup sequence. At the very beginning - really before anything is done - I check the available memory.

The data from my Intel iMac looks like this:

2024-05-17 14:34:23 Total physical Memory: 32,000 GB  
2024-05-17 14:34:23 Physical Memory used by MAX: 0,127 GB  
2024-05-17 14:34:23 Free physical Memory: 0,180 GB  
2024-05-17 14:34:23 Total virtual Memory: 31,910 GB  
2024-05-17 14:34:23 Virtual Memory used by MAX: 6,657 GB  
2024-05-17 14:34:23 Free virtual Memory: 0,180 GB

Now compare this to the M2 of the user:

2024-05-17 12:58:53 Total physical Memory: 16,000 GB  
2024-05-17 12:58:53 Physical Memory used by MAX: 0,163 GB  
2024-05-17 12:58:53 Free physical Memory: 0,074 GB  
2024-05-17 12:58:53 Total virtual Memory: 9,681 GB  
**2024-05-17 12:58:53 Virtual Memory used by MAX: 394,115 GB**  
2024-05-17 12:58:53 Free virtual Memory: 0,074 GB

What could cause the 394 GB of virtual memory?

The code for getting the memory information, which is directly out of the MBS examples:

```auto
dim theDarwin as DarwinVMStatisticsMBS = GetDarwinVMStatisticsMBS
if theDarwin = nil then Return
dim theTaskInfo as new DarwinTaskInfoMBS
if theTaskInfo = nil then Return
dim thePageSize as Double = theDarwin.Pagesize // make a double to avoid integer overflow problems

LogItem "Total physical Memory: " + FormatMemory(SystemInformationMBS.PhysicalRAM)
LogItem "Physical Memory used by MAX: " + FormatMemory(theTaskInfo.ResidentSize)
LogItem "Free physical Memory: " + FormatMemory(thePageSize * theDarwin.FreePages)
LogItem "Total virtual Memory: " + FormatMemory(thePageSize * theDarwin.InactivePages + thePageSize * theDarwin.ActivePages + thePageSize * theDarwin.FreePages + thePageSize * theDarwin.WiredPages)
LogItem "Virtual Memory used by MAX: " + FormatMemory(theTaskInfo.VirtualSize)
LogItem "Free virtual Memory: " + FormatMemory(thePageSize * theDarwin.FreePages)

```

The code that fails as result:

```auto
SQLiteIndexDBMBS.ExecuteSQL "PRAGMA cache_size = 500000" // 500 MB
SQLiteIndexDBMBS.ExecuteSQL "PRAGMA encoding = ""UTF-8""" // encoding utf8 instead of utf16

```

---

<div class="post-metadata">

**Author:** ![kevin\_g](https://forum.xojo.com/letter_avatar_proxy/v4/letter/k/65b543/32.png) [@kevin\_g](https://forum.xojo.com/u/kevin_g)\
**Post date:** [May 18, 2024, 10:23am UTC](https://forum.xojo.com/t/app-starts-using-384-gb-of-virtual-memory/80352/2 "2024-05-18T10:23:05Z")

</div>

I think your PRAGMA cache\_size statement is wrong.  
This is from the docs:  
**PRAGMA** _schema._ **cache\_size =** _pages_ **;  
PRAGMA **_schema._** cache\_size = - **_kibibytes_** ;**

So, it looks like you are allocating 500000 pages and not 500MB.

Maybe the SQLite databases on the Intel and M2 computers have different page sizes.

---

<div class="post-metadata">

**Author:** ![Rick\_Araujo](https://forum.xojo.com/user_avatar/forum.xojo.com/rick_araujo/32/251_2.png) [@Rick\_Araujo](https://forum.xojo.com/u/Rick_Araujo)\
**Post date:** [May 18, 2024, 10:57am UTC](https://forum.xojo.com/t/app-starts-using-384-gb-of-virtual-memory/80352/3 "2024-05-18T10:57:40Z")

</div>

> [@Beatrix\_Willius](#):
>
> `SQLiteIndexDBMBS.ExecuteSQL "PRAGMA cache_size = 500000" // 500 MB`

As Kevin said, the negation of the value is missing

```auto
SQLiteIndexDBMBS.ExecuteSQL "PRAGMA cache_size = -500000" // 500 MB

```

---

<div class="post-metadata">

**Author:** ![Beatrix\_Willius](https://forum.xojo.com/user_avatar/forum.xojo.com/beatrix_willius/32/282_2.png) [@Beatrix\_Willius](https://forum.xojo.com/u/Beatrix_Willius)\
**Post date:** [May 18, 2024, 11:02am UTC](https://forum.xojo.com/t/app-starts-using-384-gb-of-virtual-memory/80352/4 "2024-05-18T11:02:11Z")

</div>

The code for SQLite has worked at least half a dozen years. And it doesn’t explain why the virtual memory on start is so high.

---

<div class="post-metadata">

**Author:** ![Beatrix\_Willius](https://forum.xojo.com/user_avatar/forum.xojo.com/beatrix_willius/32/282_2.png) [@Beatrix\_Willius](https://forum.xojo.com/u/Beatrix_Willius)\
**Post date:** [May 18, 2024, 11:28am UTC](https://forum.xojo.com/t/app-starts-using-384-gb-of-virtual-memory/80352/5 "2024-05-18T11:28:29Z")

</div>

Whatever the MBS plugin is doing is rather odd. I get 394 GB of virtual memory on my M1 Air, too. So I’ll try the  
`"PRAGMA cache_size = -500000"`  
next.

---

<div class="post-metadata">

**Author:** ![kevin\_g](https://forum.xojo.com/letter_avatar_proxy/v4/letter/k/65b543/32.png) [@kevin\_g](https://forum.xojo.com/u/kevin_g)\
**Post date:** [May 18, 2024, 11:48am UTC](https://forum.xojo.com/t/app-starts-using-384-gb-of-virtual-memory/80352/6 "2024-05-18T11:48:09Z")

</div>

SQLite built into Xojo should do the same and I would have expected the Intel build to also reserve the same amount of virtual memory.

Maybe you are seeing a difference in how Intel & Apple Silicon works or possibly a SQLite issue.

---

<div class="post-metadata">

**Author:** ![Scott\_C](https://forum.xojo.com/user_avatar/forum.xojo.com/scott_c/32/19612_2.png) [@Scott\_C](https://forum.xojo.com/u/Scott_C)\
**Post date:** [May 18, 2024, 6:12pm UTC](https://forum.xojo.com/t/app-starts-using-384-gb-of-virtual-memory/80352/7 "2024-05-18T18:12:43Z")

</div>

> [@Beatrix\_Willius](#):
>
> Whatever the MBS plugin is doing is rather odd. I get 394 GB of virtual memory on my M1 Air, too.

For what it’s worth, I get similar results on my M1 Air as well.

- macOS 14.5
- MBS 24.2

I only have Mail, Safari and Xojo 2024r1.1 running with a decent size project.

```auto
Total physical Memory: 16.000 GB
Physical Memory used by MAX: 0.142 GB
Free physical Memory: 0.201 GB
Total virtual Memory: 15.045 GB
Virtual Memory used by MAX: 393.256 GB
Free virtual Memory: 0.201 GB

```

I don’t understand the numbers completely, but why is the calculation for line 3 & 6 the same (but with different labels)?

---

<div class="post-metadata">

**Author:** ![Mike\_D](https://forum.xojo.com/user_avatar/forum.xojo.com/mike_d/32/266_2.png) [@Mike\_D](https://forum.xojo.com/u/Mike_D)\
**Post date:** [May 19, 2024, 2:27pm UTC](https://forum.xojo.com/t/app-starts-using-384-gb-of-virtual-memory/80352/8 "2024-05-19T14:27:38Z")

</div>

I’m seeing something different when using an older MBS, Xojo, and Intel builds:

Runing on Intel macOS Ventura:

```auto
Xojo: 2019r1.1
MBS: MBS Xojo Plugin 21.3 (build 20576) Sun Jul 11 08:45:12 2021 (GMT)
Target: x86
Total physical Memory: 32.00 GB
Physical Memory used by MAX: 0.03 GB
Free physical Memory: 6.67 GB
Total virtual Memory: 31.13 GB
Virtual Memory used by MAX: 33.89 GB
Free virtual Memory: 6.67 GB

```

Running on M1 mac (Sonoma 14.5) under Rosetta:

```auto
Xojo: 2019r1.1
MBS: MBS Xojo Plugin 21.3 (build 20576) Sun Jul 11 08:45:12 2021 (GMT)
Target: x86
Total physical Memory: 8.00 GB
Physical Memory used by MAX: 0.02 GB
Free physical Memory: 0.13 GB
Total virtual Memory: 7.45 GB
Virtual Memory used by MAX: 33.20 GB
Free virtual Memory: 0.13 GB

```

---

<div class="post-metadata">

**Author:** ![Mike\_D](https://forum.xojo.com/user_avatar/forum.xojo.com/mike_d/32/266_2.png) [@Mike\_D](https://forum.xojo.com/u/Mike_D)\
**Post date:** [May 19, 2024, 2:32pm UTC](https://forum.xojo.com/t/app-starts-using-384-gb-of-virtual-memory/80352/9 "2024-05-19T14:32:15Z")

</div>

On my M1 mac, if I use Activity Monitor to select a process (such as “Dock”) I also see weird VM numbers:  
 ![image](https://forum.xojo.com/uploads/default/original/3X/d/f/df64e8df3b7bbbcaec6a5366d692e4fe74e24f72.jpeg)

Note how “dock” claims to also be using 393GB of VM…

---

<div class="post-metadata">

**Author:** ![Anthony\_G\_Cyphers](https://forum.xojo.com/user_avatar/forum.xojo.com/anthony_g_cyphers/32/16862_2.png) [@Anthony\_G\_Cyphers](https://forum.xojo.com/u/Anthony_G_Cyphers)\
**Post date:** [May 19, 2024, 2:54pm UTC](https://forum.xojo.com/t/app-starts-using-384-gb-of-virtual-memory/80352/10 "2024-05-19T14:54:41Z")

</div>

Seeing this on my M2 Max with no apps running.

 ![image](https://forum.xojo.com/uploads/default/original/3X/4/f/4fe7499701af7f2d884985943dcf625af3cd0c27.png)

And here’s a fresh launch of Xojo before loading a project:

 ![image](https://forum.xojo.com/uploads/default/original/3X/2/5/258ca924c36b08bdae7103f34c07800b5936779e.png)

Just looks like macOS on Apple Silicon is reporting the virtual memory values wrong.

---

<div class="post-metadata">

**Author:** ![Björn\_Eiríksson](https://forum.xojo.com/letter_avatar_proxy/v4/letter/b/da6949/32.png) [@Björn\_Eiríksson](https://forum.xojo.com/u/Bj%C3%B6rn_Eir%C3%ADksson)\
**Post date:** [May 19, 2024, 3:14pm UTC](https://forum.xojo.com/t/app-starts-using-384-gb-of-virtual-memory/80352/11 "2024-05-19T15:14:28Z")

</div>

Likely just using it differently, probably like how iOS does it in some way. (making use of the fast SSD to make people think its ok to have low amount of RAM)

---

<div class="post-metadata">

**Author:** ![Christian\_Schmitz](https://forum.xojo.com/user_avatar/forum.xojo.com/christian_schmitz/32/158_2.png) [@Christian\_Schmitz](https://forum.xojo.com/u/Christian_Schmitz)\
**Post date:** [May 19, 2024, 3:16pm UTC](https://forum.xojo.com/t/app-starts-using-384-gb-of-virtual-memory/80352/12 "2024-05-19T15:16:22Z")

</div>

That is just the address space, not actual pages in use.

You may ignore it.

---

<div class="post-metadata">

**Author:** ![Anthony\_G\_Cyphers](https://forum.xojo.com/user_avatar/forum.xojo.com/anthony_g_cyphers/32/16862_2.png) [@Anthony\_G\_Cyphers](https://forum.xojo.com/u/Anthony_G_Cyphers)\
**Post date:** [May 19, 2024, 3:17pm UTC](https://forum.xojo.com/t/app-starts-using-384-gb-of-virtual-memory/80352/13 "2024-05-19T15:17:39Z")

</div>

This makes more sense. It’s certainly not fakery to shore up physical memory in my case. I have 33.37GB of free physical RAM right now. And I certainly am not running any app that would use 385GB of memory. It is still misleading.

---

<div class="post-metadata">

**Author:** ![TimStreater](https://forum.xojo.com/user_avatar/forum.xojo.com/timstreater/32/586_2.png) [@TimStreater](https://forum.xojo.com/u/TimStreater)\
**Post date:** [May 19, 2024, 3:45pm UTC](https://forum.xojo.com/t/app-starts-using-384-gb-of-virtual-memory/80352/14 "2024-05-19T15:45:49Z")

</div>

Won’t this include system .dylibs that are mapped into your address space?

---

<div class="post-metadata">

**Author:** ![Scott\_C](https://forum.xojo.com/user_avatar/forum.xojo.com/scott_c/32/19612_2.png) [@Scott\_C](https://forum.xojo.com/u/Scott_C)\
**Post date:** [May 19, 2024, 3:50pm UTC](https://forum.xojo.com/t/app-starts-using-384-gb-of-virtual-memory/80352/15 "2024-05-19T15:50:48Z")

</div>

> [@Mike\_D](#):
>
> Running on M1 mac (Sonoma 14.5) under Rosetta:

Good point. If I change the Build from “Universal” to “x86 64-bit”, then I get the following:

```auto
Total physical Memory: 16.000 Gb
Physical Memory used by MAX: 0.116 Gb
Free physical Memory: 0.291 Gb
Total virtual Memory: 14.968 Gb
Virtual Memory used by MAX: 34.222 Gb // ~350 less Gb of space available
Free virtual Memory: 0.291 Gb

```

Silicon/ARM builds are obviously handled differently. Interesting observations…

---

<div class="post-metadata">

**Author:** ![Rick\_Araujo](https://forum.xojo.com/user_avatar/forum.xojo.com/rick_araujo/32/251_2.png) [@Rick\_Araujo](https://forum.xojo.com/u/Rick_Araujo)\
**Post date:** [May 19, 2024, 3:58pm UTC](https://forum.xojo.com/t/app-starts-using-384-gb-of-virtual-memory/80352/16 "2024-05-19T15:58:41Z")

</div>

So, it is not an SQLite issue, but a macOS ARM issue/behavior.
