# Memory error when running stan

**URL:** <https://discourse.mc-stan.org/t/memory-error-when-running-stan/21887>\
**Category:** General\
**Created:** [April 15, 2021, 2:29am UTC](https://discourse.mc-stan.org/t/memory-error-when-running-stan/21887 "2021-04-15T02:29:36Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![stan\_beginer](https://avatars.discourse-cdn.com/v4/letter/s/f0a364/32.png) [@stan\_beginer](https://discourse.mc-stan.org/u/stan_beginer)\
**Post date:** [April 15, 2021, 2:29am UTC](https://discourse.mc-stan.org/t/memory-error-when-running-stan/21887/1 "2021-04-15T02:29:36Z")

</div>

Hi,

I have performed some Stan modeling using Windows and Rstan. The code could work before and but recently I found some error like:

Error: cannot allocate vector of size 944 Kb

It seems that it’s memory allocatin error and the code has not changed while the data size has increased a little bit (like from 25000 observations changing to 27000 observations). My computer have 32 GB memory but specifying

```
memory.limit(size = 30000)

```

will not work. Not sure what’s going on and any advice?

Thx!

---

<div class="post-metadata">

**Author:** ![mike-lawrence](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/mike-lawrence/32/59_2.png) [@mike-lawrence](https://discourse.mc-stan.org/u/mike-lawrence)\
**Post date:** [April 15, 2021, 11:48am UTC](https://discourse.mc-stan.org/t/memory-error-when-running-stan/21887/2 "2021-04-15T11:48:47Z")

</div>

Does this occur while the model is sampling, or while you are doing post-sampling operations on the fitted rstan object?

---

<div class="post-metadata">

**Author:** ![stan\_beginer](https://avatars.discourse-cdn.com/v4/letter/s/f0a364/32.png) [@stan\_beginer](https://discourse.mc-stan.org/u/stan_beginer)\
**Post date:** [April 19, 2021, 2:05am UTC](https://discourse.mc-stan.org/t/memory-error-when-running-stan/21887/3 "2021-04-19T02:05:54Z")

</div>

Hi,

This occured during the model is sampling and thus there is no rstan object outputed.

---

<div class="post-metadata">

**Author:** ![mike-lawrence](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/mike-lawrence/32/59_2.png) [@mike-lawrence](https://discourse.mc-stan.org/u/mike-lawrence)\
**Post date:** [April 19, 2021, 11:32am UTC](https://discourse.mc-stan.org/t/memory-error-when-running-stan/21887/4 "2021-04-19T11:32:01Z")

</div>

Can pull up Task manager and watch the RAM usage of the model exe while it is sampling?

---

<div class="post-metadata">

**Author:** ![stan\_beginer](https://avatars.discourse-cdn.com/v4/letter/s/f0a364/32.png) [@stan\_beginer](https://discourse.mc-stan.org/u/stan_beginer)\
**Post date:** [April 20, 2021, 12:23am UTC](https://discourse.mc-stan.org/t/memory-error-when-running-stan/21887/5 "2021-04-20T00:23:35Z")

</div>

It seems to be a good idea but the model takes hours to run, any idea to automatically monitor the RAM usage?

Thx!

---

<div class="post-metadata">

**Author:** ![mike-lawrence](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/mike-lawrence/32/59_2.png) [@mike-lawrence](https://discourse.mc-stan.org/u/mike-lawrence)\
**Post date:** [April 20, 2021, 11:06am UTC](https://discourse.mc-stan.org/t/memory-error-when-running-stan/21887/6 "2021-04-20T11:06:08Z")

</div>

Maybe try [perfmon](https://www.instantfundas.com/2012/03/how-to-record-cpu-and-memory-usage-over.html)? I don’t think that article shows it, but you can make it process-specific.

---

<div class="post-metadata">

**Author:** ![stan\_beginer](https://avatars.discourse-cdn.com/v4/letter/s/f0a364/32.png) [@stan\_beginer](https://discourse.mc-stan.org/u/stan_beginer)\
**Post date:** [April 22, 2021, 1:54am UTC](https://discourse.mc-stan.org/t/memory-error-when-running-stan/21887/7 "2021-04-22T01:54:49Z")

</div>

Thanks so much!
