### Is there an existing issue for this?

- [X] I have searched the existing issues

### Current behaviour

```
bitcoind_1  | 2023-09-09T10:04:30Z UpdateTip: new best=00000000000000000a1f0a5dc852ab81d720fb9dceec91bc42f1461a3cf4d3d5 height=371331 version=0x00000003 log2_work=83.254030 tx=81012235 date='2015-08-24T15:55:06Z' progress=0.093034 cache=226.8MiB(31141716txo)
bitcoind_1  | 2023-09-09T10:04:31Z UpdateTip: new best=000000000000000000509e83cabd4f3f02c62638470357eff53275c9532da94f height=371332 version=0x00000003 log2_work=83.254059 tx=81013228 date='2015-08-24T16:03:31Z' progress=0.093036 cache=226.8MiB(31141264txo)
bitcoind_1  | 2023-09-09T10:04:31Z UpdateTip: new best=00000000000000001434c5b3995a1c065fc434fdd1098dbb65020bdf57d90f2a height=371333 version=0x00000003 log2_work=83.254088 tx=81015020 date='2015-08-24T16:21:46Z' progress=0.093038 cache=226.8MiB(31140795txo)
bitcoind_1  | 2023-09-09T10:04:31Z UpdateTip: new best=00000000000000000796a4bd624aeaf6d81b24e666e5db3e7fa62f094df3bc96 height=371334 version=0x00000003 log2_work=83.254117 tx=81015365 date='2015-08-24T16:23:46Z' progress=0.093038 cache=226.8MiB(31141560txo)
bitcoind_1  | 2023-09-09T10:04:32Z UpdateTip: new best=000000000000000006b17425eda94c210ef5111c20c10d1829829d0eeaf905a9 height=371335 version=0x00000003 log2_work=83.254146 tx=81016765 date='2015-08-24T16:35:39Z' progress=0.093040 cache=226.8MiB(31142260txo)
bitcoind_1  | 2023-09-09T10:04:32Z UpdateTip: new best=00000000000000000c684f7fbcbd0bf42879ca1143844d34c5d4ae28358fb41f height=371336 version=0x00000003 log2_work=83.254175 tx=81017385 date='2015-08-24T16:44:52Z' progress=0.093040 cache=226.8MiB(31141393txo)
bitcoind_1  | 2023-09-09T10:04:32Z UpdateTip: new best=00000000000000001004395fb5a59a4d44e51e7f9ff3504c2a5d6e7f06885680 height=371337 version=0x00000003 log2_work=83.254204 tx=81017610 date='2015-08-24T17:00:31Z' progress=0.093041 cache=226.8MiB(31135360txo)
bitcoind_1  | 2023-09-09T10:04:32Z UpdateTip: new best=00000000000000000fb4a9c39dbbf671d79b0eee48cb2f3c85ae39a5005e82d6 height=371338 version=0x00000003 log2_work=83.254234 tx=81019260 date='2015-08-24T17:14:47Z' progress=0.093042 cache=226.8MiB(31134479txo)
bitcoind_1  | 2023-09-09T10:04:33Z UpdateTip: new best=000000000000000006c32b4c4231d2c129a43fae47e2f729530baa1e198a71b8 height=371339 version=0x00000003 log2_work=83.254263 tx=81020779 date='2015-08-24T17:18:04Z' progress=0.093044 cache=226.8MiB(31133741txo)
bitcoind_1  | 2023-09-09T10:04:33Z UpdateTip: new best=0000000000000000101b9824fbbbf52b158c04d33aeab910954cfce6c4c658a6 height=371340 version=0x00000003 log2_work=83.254292 tx=81021579 date='2015-08-24T17:23:07Z' progress=0.093045 cache=226.8MiB(31133299txo)
bitcoind_1  | 2023-09-09T10:04:33Z UpdateTip: new best=000000000000000008aa6cf51dfde20be1d54e671494a44fb7f252fd4e913162 height=371341 version=0x00000003 log2_work=83.254321 tx=81023741 date='2015-08-24T17:44:26Z' progress=0.093048 cache=226.8MiB(31133550txo)
bitcoind_1  | 2023-09-09T10:04:33Z Error: Out of memory. Terminating.
bitcoind_1  | terminate called without an active exception
```

Memory usage at the time it crashed:

```
11:02:02    kbmemfree   kbavail kbmemused  %memused kbbuffers  kbcached  kbcommit   %commit  kbactive   kbinact   kbdirty
11:02:07       231712   3738772   4107264     51.34     26084   3429852   4710940     38.63   4251760   3238784     93412
11:02:12       231144   3711664   4135192     51.69     25796   3403248   4788664     39.27   4272024   3212576     30548
11:02:17       213516   3723396   4123420     51.54     25812   3432576   4785520     39.24   4268160   3241888     59588
11:02:22       218356   3730188   4116724     51.46     25776   3434476   4786956     39.26   4269748   3243840     89336
11:02:27       228116   3730640   4116264     51.45     25760   3425196   4780584     39.20   4266152   3234516    120972
11:02:32       204724   3713548   4133328     51.67     25456   3431848   4788772     39.27   4272332   3240804    147996
11:02:37       224444   3716164   4131268     51.64     24652   3415048   4788176     39.27   4270996   3223820     15020
11:02:42       253200   3719404   4129136     51.62     25084   3388780   4790644     39.29   4272240   3199076     30304
11:02:47       232160   3710116   4138496     51.73     25476   3399732   4789644     39.28   4273788   3210472     50216
11:02:52       205368   3713000   4135524     51.70     25828   3428468   4789020     39.27   4273788   3239492     76856
11:02:57       211364   3703688   4144752     51.81     25868   3413388   4791064     39.29   4277112   3224240     95920
11:03:02       226660   3704636   4143856     51.80     25712   3399384   4789360     39.28   4276240   3210116    117380
11:03:07       215064   3701712   4146716     51.84     26112   3407656   4795896     39.33   4280708   3218744    145936
11:03:12       207360   3706752   4142552     51.78     26256   3418984   4797584     39.34   4280072   3231016     18036
11:03:17       217064   3715432   4133840     51.67     26256   3417940   4795044     39.32   4279848   3229952     43368
11:03:22       217284   3712796   4136340     51.71     26264   3415216   4794976     39.32   4280332   3227112     73268
11:03:27       210508   3704160   4144884     51.81     26272   3413412   4794444     39.32   4279876   3225244     99088
11:03:32       224988   3703424   4145876     51.82     26232   3398252   4799232     39.36   4283672   3210292    127728
11:03:37       206192   3713316   4136632     51.71     26264   3425568   4799268     39.36   4282624   3238272    148084
11:03:42       212172   3723348   4126960     51.59     26288   3429108   4791204     39.29   4277816   3242172     26408
11:03:47       240548   3725292   4125248     51.57     26276   3403016   4792492     39.30   4280592   3216308     56844
11:03:52       203952   3710732   4139928     51.75     26308   3424324   4797664     39.34   4282804   3237752     78048
11:03:57       215576   3716332   4134396     51.68     26324   3418392   4800320     39.37   4283368   3231808    100300
11:04:02       205540   3705280   4145444     51.82     26348   3417292   4803828     39.39   4285928   3230756    115348
11:04:07       213100   3704864   4145792     51.82     26340   3409512   4804740     39.40   4287800   3222948    135688
11:04:12       214424   3709124   4141832     51.77     26356   3411916   4800868     39.37   4286328   3225704     16632
11:04:17       204652   3702028   4148892     51.86     26356   3414520   4800116     39.36   4287616   3228256     47500
11:04:22       213052   3681992   4168880     52.11     26356   3386772   4812260     39.46   4297872   3200484     77004
11:04:27       208780   3681020   4169712     52.12     26348   3390016   4822388     39.55   4305700   3203616    108244
11:04:32       200124   3665384   4185420     52.32     25968   3383348   4824268     39.56   4307804   3196628    124520
11:04:37       215756   3665912   4184724     52.31     23580   3369252   4824364     39.56   4307996   3180076    494028
11:04:42      1971324   3617144   4184700     52.31     19708   1641096   4822548     39.55   4307480   1448108    654576
11:04:47      1740108   3612528   4189324     52.37     19728   1862428   4822548     39.55   4307484   1669464    744892
11:04:52      1581404   3611644   4190256     52.38     19740   2015900   4822548     39.55   4307488   1823000    762952
11:04:57      1454928   3611664   4190204     52.38     19756   2138980   4822548     39.55   4307488   1946068    742872
11:05:02      1376868   3631312   4170632     52.13     19768   2233992   4784572     39.24   4286420   2041124    706744
11:05:07      1267544   3630916   4170936     52.14     19780   2340000   4784572     39.24   4286432   2147080    667320
11:05:12      1155152   3631364   4170732     52.14     19792   2449516   4784572     39.24   4286300   2256872    635532
11:05:17      1045588   3631688   4170492     52.13     19804   2556456   4784572     39.24   4286268   2363868    603200
11:05:22       913040   3632364   4169824     52.12     19816   2685936   4784572     39.24   4286284   2493380    581092
11:05:27       843540   3630500   4171756     52.15     19836   2751728   4786388     39.25   4286796   2559224    519916
11:05:32       688180   3629032   4173132     52.17     19848   2901696   4784572     39.24   4286304   2709140    522620
11:05:37       558748   3628956   4173360     52.17     19860   3027208   4784572     39.24   4286312   2834752    508664
11:05:42       392452   3628156   4174080     52.18     19872   3188348   4784572     39.24   4286332   2995828    538724
11:05:47       239560   3627644   4174488     52.18     19880   3336584   4786388     39.25   4286840   3144000    531308
11:05:52       203756   3628228   4174148     52.18     19900   3371784   4784572     39.24   4286308   3179412    498168
11:05:57       133836   3628928   4173400     52.17     19920   3440480   4784572     39.24   4286312   3248100    430364
11:06:02        94968   3629700   4172180     52.15     19868   3479136   4784572     39.24   4286384   3286264    359504
11:06:07        87700   3679172   4172144     52.15     19880   3485776   4784572     39.24   4286480   3293272    472160
11:06:12        79144   3679704   4171608     52.15     19892   3494220   4784572     39.24   4286488   3301728    505572
11:06:17        75152   3680568   4170708     52.14     19908   3498656   4784572     39.24   4286500   3306124    562968
11:06:22        79244   3631112   4171068     52.14     19920   3493912   4784572     39.24   4286512   3301244    570720
11:06:27        75452   3679644   4167668     52.10     19908   3500708   4784572     39.24   4287352   3303904    553348
11:06:32        74328   3680424   4166868     52.09     19916   3502296   4784572     39.24   4287512   3305468    585032
```

It never gets to use the swap (but it also shouldn't, using RAM usage at only 50%:
```
$ free -h
               total        used        free      shared  buff/cache   available
Mem:           7.6Gi       392Mi       3.3Gi       1.0Mi       3.9Gi       7.1Gi
Swap:          4.0Gi          0B       4.0Gi
```

My bitcoin.conf:
```
server=1
rpcuser=****************
rpcpassword=****************

[main]
rpcbind=0.0.0.0
rpcallowip=0.0.0.0/0
rpcport=8332
txindex=1
zmqpubrawblock=tcp://0.0.0.0:28332
zmqpubrawtx=tcp://0.0.0.0:28333

[test]
rpcbind=0.0.0.0
rpcallowip=0.0.0.0/0
testnet=0
rpcport=18332
zmqpubrawblock=tcp://0.0.0.0:38332
zmqpubrawtx=tcp://0.0.0.0:38333
```

I have tried to play around with **dbcache**, **maxsigcachesize**, **maxconnections**, and **rpcthreads**. Same error, exactly at ~9% sync.

### Expected behaviour

For it to run smoothly without crashing.

### Steps to reproduce

**On a Raspberry Pi 4, 8GB version.**

Add the following docker-compose.yaml:

```
version: '3'
services:
  bitcoind:
    build: .
    volumes:
      - ./bitcoind_data:/root/.bitcoin
    restart: always
```

Put the bitcoin.conf inside `./bitcoind_data` relative to where you placed the compose file:

```
server=1
rpcuser=****************
rpcpassword=****************

[main]
rpcbind=0.0.0.0
rpcallowip=0.0.0.0/0
rpcport=8332
txindex=1
zmqpubrawblock=tcp://0.0.0.0:28332
zmqpubrawtx=tcp://0.0.0.0:28333

[test]
rpcbind=0.0.0.0
rpcallowip=0.0.0.0/0
testnet=0
rpcport=18332
zmqpubrawblock=tcp://0.0.0.0:38332
zmqpubrawtx=tcp://0.0.0.0:38333
```

And the following Dockerfile in `.`:
```
FROM debian:trixie-20230814-slim

RUN apt-get update
RUN apt-get install -y git build-essential libtool autotools-dev automake pkg-config bsdmainutils python3 libevent-dev libboost-dev libsqlite3-dev libzmq3-dev libqt5gui5 libqt5core5a libqt5dbus5 qttools5-dev qttools5-dev-tools

RUN git clone -b master https://github.com/bitcoin/bitcoin.git

WORKDIR bitcoin

RUN ./autogen.sh
RUN ./configure
RUN make -j "$(($(nproc)+1))"
RUN make install
RUN apt-get install -y tree

WORKDIR /root

ENTRYPOINT ["bitcoind"]
```

Then run `docker-compose up` and wait about 40 mins, until it reaches a point (in my case progress ~0.09, ~250mb cache) and terminates the process.

### Relevant log output

```
bitcoind_1  | 2023-09-09T10:04:30Z UpdateTip: new best=00000000000000000a1f0a5dc852ab81d720fb9dceec91bc42f1461a3cf4d3d5 height=371331 version=0x00000003 log2_work=83.254030 tx=81012235 date='2015-08-24T15:55:06Z' progress=0.093034 cache=226.8MiB(31141716txo)
bitcoind_1  | 2023-09-09T10:04:31Z UpdateTip: new best=000000000000000000509e83cabd4f3f02c62638470357eff53275c9532da94f height=371332 version=0x00000003 log2_work=83.254059 tx=81013228 date='2015-08-24T16:03:31Z' progress=0.093036 cache=226.8MiB(31141264txo)
bitcoind_1  | 2023-09-09T10:04:31Z UpdateTip: new best=00000000000000001434c5b3995a1c065fc434fdd1098dbb65020bdf57d90f2a height=371333 version=0x00000003 log2_work=83.254088 tx=81015020 date='2015-08-24T16:21:46Z' progress=0.093038 cache=226.8MiB(31140795txo)
bitcoind_1  | 2023-09-09T10:04:31Z UpdateTip: new best=00000000000000000796a4bd624aeaf6d81b24e666e5db3e7fa62f094df3bc96 height=371334 version=0x00000003 log2_work=83.254117 tx=81015365 date='2015-08-24T16:23:46Z' progress=0.093038 cache=226.8MiB(31141560txo)
bitcoind_1  | 2023-09-09T10:04:32Z UpdateTip: new best=000000000000000006b17425eda94c210ef5111c20c10d1829829d0eeaf905a9 height=371335 version=0x00000003 log2_work=83.254146 tx=81016765 date='2015-08-24T16:35:39Z' progress=0.093040 cache=226.8MiB(31142260txo)
bitcoind_1  | 2023-09-09T10:04:32Z UpdateTip: new best=00000000000000000c684f7fbcbd0bf42879ca1143844d34c5d4ae28358fb41f height=371336 version=0x00000003 log2_work=83.254175 tx=81017385 date='2015-08-24T16:44:52Z' progress=0.093040 cache=226.8MiB(31141393txo)
bitcoind_1  | 2023-09-09T10:04:32Z UpdateTip: new best=00000000000000001004395fb5a59a4d44e51e7f9ff3504c2a5d6e7f06885680 height=371337 version=0x00000003 log2_work=83.254204 tx=81017610 date='2015-08-24T17:00:31Z' progress=0.093041 cache=226.8MiB(31135360txo)
bitcoind_1  | 2023-09-09T10:04:32Z UpdateTip: new best=00000000000000000fb4a9c39dbbf671d79b0eee48cb2f3c85ae39a5005e82d6 height=371338 version=0x00000003 log2_work=83.254234 tx=81019260 date='2015-08-24T17:14:47Z' progress=0.093042 cache=226.8MiB(31134479txo)
bitcoind_1  | 2023-09-09T10:04:33Z UpdateTip: new best=000000000000000006c32b4c4231d2c129a43fae47e2f729530baa1e198a71b8 height=371339 version=0x00000003 log2_work=83.254263 tx=81020779 date='2015-08-24T17:18:04Z' progress=0.093044 cache=226.8MiB(31133741txo)
bitcoind_1  | 2023-09-09T10:04:33Z UpdateTip: new best=0000000000000000101b9824fbbbf52b158c04d33aeab910954cfce6c4c658a6 height=371340 version=0x00000003 log2_work=83.254292 tx=81021579 date='2015-08-24T17:23:07Z' progress=0.093045 cache=226.8MiB(31133299txo)
bitcoind_1  | 2023-09-09T10:04:33Z UpdateTip: new best=000000000000000008aa6cf51dfde20be1d54e671494a44fb7f252fd4e913162 height=371341 version=0x00000003 log2_work=83.254321 tx=81023741 date='2015-08-24T17:44:26Z' progress=0.093048 cache=226.8MiB(31133550txo)
bitcoind_1  | 2023-09-09T10:04:33Z Error: Out of memory. Terminating.
bitcoind_1  | terminate called without an active exception
```

### How did you obtain Bitcoin Core

Compiled from source

### What version of Bitcoin Core are you using?

25.0

### Operating system and version

Raspbian Light
Linux raspberrypi 6.1.21-v8+ #1642 SMP PREEMPT Mon Apr  3 17:24:16 BST 2023 aarch64 GNU/Linux

### Machine specifications

https://www.raspberrypi.com/products/raspberry-pi-4-model-b/specifications/
*   This chunk is used to carve out blocks.
 *
 * * Block sizes or alignments that can not be served by the pools are allocated
 *   and deallocated by operator new().
 *
 * PoolResource is not thread-safe. It is intended to be used by PoolAllocator.
 *
 * @tparam MAX_BLOCK_SIZE_BYTES Maximum size to allocate with the pool. If larger
 *         sizes are requested, allocation falls back to new().
 *
 * @tparam ALIGN_BYTES Required alignment for the allocations.
 *
 * An example: If you create a PoolResource<128, 8>(262144) and perform a bunch of
 * allocations and deallocate 2 blocks with size 8 bytes, and 3 blocks with size 16,
 * the members will look like this:
 *
 *     m_free_lists                         m_allocated_chunks
 *        ┌───┐                                ┌───┐  ┌────────────-------──────┐
 *        │   │  blocks                        │   ├─►│    262144 B             │
 *        │   │  ┌─────┐  ┌─────┐              └─┬─┘  └────────────-------──────┘
 *        │ 1 ├─►│ 8 B ├─►│ 8 B │                │
 *        │   │  └─────┘  └─────┘                :
 *        │   │                                  │
 *        │   │  ┌─────┐  ┌─────┐  ┌─────┐       ▼
 *        │ 2 ├─►│16 B ├─►│16 B ├─►│16 B │     ┌───┐  ┌─────────────────────────┐
 *        │   │  └─────┘  └─────┘  └─────┘     │   ├─►│          ▲              │ ▲
 *        │   │                                └───┘  └──────────┬──────────────┘ │
 *        │ . │                                                  │    m_available_memory_end
 *        │ . │                                         m_available_memory_it
 *        │ . │