# Failed to allocate memory Error

**URL:** https://discourse.itk.org/t/failed-to-allocate-memory-error/1930
**Category:** Beginner Questions
**Created:** [May 31, 2019, 1:32pm UTC](https://discourse.itk.org/t/failed-to-allocate-memory-error/1930 "2019-05-31T13:32:30Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![EE18D504\_SINDHURA\_C](https://discourse.itk.org/letter_avatar_proxy/v4/letter/e/b3f665/32.png) [@EE18D504\_SINDHURA\_C](https://discourse.itk.org/u/EE18D504_SINDHURA_C)
#### Post date: [May 31, 2019, 1:32pm UTC](https://discourse.itk.org/t/failed-to-allocate-memory-error/1930/1 "2019-05-31T13:32:30Z")

</div>

I was trying to execute the DeformableRegistration15.cxx on two brain CT images.  
Pixel Type is short. I get this error when i execute it.  
Please help me with thins.

 ![image](https://discourse.itk.org/uploads/default/original/1X/0f40173276705917dad8aa30212c30042c9715e0.png)

---

<div class="post-metadata">

### Author: ![Niels\_Dekker](https://discourse.itk.org/letter_avatar_proxy/v4/letter/n/9d8465/32.png) [@Niels\_Dekker](https://discourse.itk.org/u/Niels_Dekker)
#### Post date: [May 31, 2019, 2:21pm UTC](https://discourse.itk.org/t/failed-to-allocate-memory-error/1930/2 "2019-05-31T14:21:21Z")

</div>

> [@EE18D504\_SINDHURA\_C](#):
>
> I was trying to execute the DeformableRegistration15.cxx on two brain CT images.  
> Pixel Type is short. I get this error when i execute it.

I’m sorry I don’t have the answer, but I just wonder:

1. How large are these two CT images? How large are the actual CT files?
2. Did you compile for 32-bit (x86) or 64-bit (x64)? Debug or Release?
3. Which version of ITK do you use?

Good luck!

---

<div class="post-metadata">

### Author: ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)
#### Post date: [May 31, 2019, 3:59pm UTC](https://discourse.itk.org/t/failed-to-allocate-memory-error/1930/3 "2019-05-31T15:59:58Z")

</div>

That error message indicates that the images are too big for your computer’s memory. You could try increasing your swap file size.

---

<div class="post-metadata">

### Author: ![IlvaHou](https://discourse.itk.org/letter_avatar_proxy/v4/letter/i/f19dbf/32.png) [@IlvaHou](https://discourse.itk.org/u/IlvaHou)
#### Post date: [January 30, 2024, 8:12am UTC](https://discourse.itk.org/t/failed-to-allocate-memory-error/1930/4 "2024-01-30T08:12:53Z")

</div>

Hi,

I encounter a similar problem and was wondering how to solve by using your questions:

1. I am using 4D MR images that are around 1500 MB
2. I compiled for 32-bit, Release, using Visual Studio 2017
3. I am using ITK 4.8

I know that it is an old version of Visual Studio and an old version of ITK, but I need this because other tooling I use is based on these old versions. Compiling for 64-bit, following [How to: Configure Visual Studio C++ projects to Target 64-Bit, x64 Platforms | Microsoft Learn](https://learn.microsoft.com/en-us/cpp/build/how-to-configure-visual-cpp-projects-to-target-64-bit-platforms?view=msvc-170), did not work as my Visual Studio application keeps freezing when I try to do this after loading my .sln file…

I also already increased my swap file size to a range of 10000 to 70000 MB, as suggested below.

But I am still running into problems.

---

<div class="post-metadata">

### Author: ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)
#### Post date: [January 30, 2024, 2:30pm UTC](https://discourse.itk.org/t/failed-to-allocate-memory-error/1930/5 "2024-01-30T14:30:12Z")

</div>

Normally, 32-bit Windows reserves 2GB of user-space memory for system use. I think that policy was abandoned sometime, but there is still [memory fragmentation](https://stackoverflow.com/questions/1684004/heap-fragmentation-and-windows-memory-manager), which makes allocating 1.5GB image far from a sure thing.

I switched to compiling for 64-bit address space long before Visual Studio 2017 came around. I don’t remember any particular issues with it. We did recently drop support for VS2017, so if you insist on using it, use a bit older version of ITK such as 5.3 or 5.2. The best way to build is the [usual CMake process](https://preshing.com/20170511/how-to-build-a-cmake-based-project/). Just make sure to pick the 64-bit toolset. If your VS is freezing when opening a solution, you might need to have more RAM in your computer. If that is not an option, try opening “C:\Dev\ITK-build\Examples\RegistrationITKv4\ITKv4ImageRegistration.sln” instead of “C:\Dev\ITK-build\ITK.sln”.
