none
Increasing the HEAP size in .NET Framework RRS feed

  • Question

  • Is there a configuration parameter to increase the heap size, especially for 64-bit OS? Or how do I go beyond the default heap size?

    Thanks,

    SP


    SP

    Tuesday, October 22, 2013 6:40 PM

Answers

  • Hi Apastambha,

    .Net does that automatically. If you want to create it by yourself, please refer to http://msdn.microsoft.com/en-us/library/ms810603.aspx to see the Heap Memory API.

    Could you please tell me why you need to increase the Heap size? Did you have reached the limit of the memory in your app? The process limit is 2GB on 32-bit, unless you use the /3GB boot switch. Rethink your algorithm, or perhaps a change to a 64 bit machine might help.

    Hope useful to you.

    Best Regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, October 23, 2013 9:08 AM
    Moderator

All replies

  • Hi Apastambha,

    .Net does that automatically. If you want to create it by yourself, please refer to http://msdn.microsoft.com/en-us/library/ms810603.aspx to see the Heap Memory API.

    Could you please tell me why you need to increase the Heap size? Did you have reached the limit of the memory in your app? The process limit is 2GB on 32-bit, unless you use the /3GB boot switch. Rethink your algorithm, or perhaps a change to a 64 bit machine might help.

    Hope useful to you.

    Best Regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, October 23, 2013 9:08 AM
    Moderator
  • Yes, the 32-bit application is running on the 64-bit OS (W2K8). The application is using the managed .net framework 4.0 where the heap size is limited to 2 GB, as per experts. From the performance counters, I am finding lot of contentions (> 50%) within the .net CLR. The response times are increasing, though there is plenty of room for RAM (about ~ 14GB available) and CPU (utilization is only  < 20 % at peaks). GC seems to be kicked in several times to release memory in the managed Heap. I am wondering whether there are any parameters to increase heap or some other parameter to ease the pressure on CLR.

    One of the options for 32-bit app is to increase ram to 4GB using the registry parameter. However, I am not sure whether it improves the CLR performance. I don't know what is the down side of using 4GB option. Any thoughts?

    HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Memory Management\AllocationPreference

    http://msdn.microsoft.com/en-us/library/bb613473(VS.85).aspx

    http://msdn.microsoft.com/en-us/library/aa366778.aspx


    SP


    • Edited by Apastambha Thursday, October 31, 2013 7:03 PM
    Wednesday, October 30, 2013 11:06 AM
  • >I don't know what is the down side of using 4GB option. Any thoughts?

    Those links are not relevant.  For a 32bit application on 64bit Windows to get access to the whole 4GB Virtual Address Space, it must have the /LARGEADDRESSAWARE flag in the PE header.

    For a .NET app you can't set this at build time, but you can after using EDITBIN.

    The downside is that it's not guaranteed that your code will work correctly with 4GB.  Historically some 32bit apps have used the high-order bit in pointers for other purposes, and so you have to opt-in to the larger address space. 

    So whatever legacy code is preventing you from having a 64bit app may also prevent you from having a /LARGEADDRESSAWARE app.

    David


    David http://blogs.msdn.com/b/dbrowne/

    Wednesday, October 30, 2013 11:41 AM
  • Thanks for quick response. What would be the other options to tune .NET 4.0 framework on the 64-bit machine? The performance counters are indicating that heap is beaten up.


    SP

    Wednesday, October 30, 2013 1:58 PM
  • >What would be the other options

    Recompile your app for 64bit.

    David


    David http://blogs.msdn.com/b/dbrowne/

    Wednesday, October 30, 2013 2:58 PM
  • However, what is the default heapsize for .NET framework 4.0?

    SP

    Thursday, October 31, 2013 4:55 PM
  • There is no default heap size for .NET framework 4.0.  .NET will grow the managed heap as needed.

    David


    David http://blogs.msdn.com/b/dbrowne/

    Thursday, October 31, 2013 5:19 PM
  • It was compiled for anycpu

    SP

    Thursday, October 31, 2013 8:08 PM
  • >It was compiled for anycpu

    anycpu or anycpu32bitpreferred?

    What AnyCPU Really Means As Of .NET 4.5 and Visual Studio 11

    Can you verify whether it's running in a 32bit process or a 64bit process?

    David


    David http://blogs.msdn.com/b/dbrowne/

    Thursday, October 31, 2013 8:30 PM
  • That is what was struggling with. How do I verify that it is running in a 32/64 process?

    Thanks.


    SP

    Thursday, October 31, 2013 9:55 PM
  • Hi Apastambha,

    Please refer to this page to see how to determine if a .NET app is 32 or 64 bit. http://stackoverflow.com/questions/3782191/how-do-i-determine-if-a-net-application-is-32-or-64-bit.

    Best Regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, November 1, 2013 6:38 AM
    Moderator
  • I used process explorer to find out that. The application process is running under 64-bit. Then why I am not seeing the ram utilization more than 2GB? Also, I am seeing "% time in GC" is more than 40%, though I have 14GB available memory. Why GC should be kicked in?  It there a way to improve CLR performance? 

    SP

    Friday, November 1, 2013 11:30 AM
  • > I am seeing "% time in GC" is more than 40%, though I have 14GB available memory. Why GC should be kicked in?

    If GC is running a lot that typically means your app is creating a lot of garbage.  .NET doesn't want to just grow the heaps if they are constantly full of garbage, because that would waste memory and at some point you'd run out and have a 14GB heap to collect.

    It may be that your app only needs 1GB of RAM at any one time, but is constantly allocating memory and creating garbage.

    >It there a way to improve CLR performance? 

    I would start by doing memory profiling on the app to find the bits of code creating the most garbage.  Hopefully you can find a way to reduce the allocations or perhaps reuse some of the allocated memory.  byte[]'s are particularly good candidates for pooling and reuse.

    David


    David http://blogs.msdn.com/b/dbrowne/

    Friday, November 1, 2013 1:35 PM
  • I would certainly consider for app code walk-through in next steps.  From the platform side, I am wondering how "managed" framework would help the developer further. I assumed that GC won't kick in, at least until it reaches in the neighborhood of 4GB for the 64-bit process.

    Thanks.


    SP


    • Edited by Apastambha Friday, November 1, 2013 8:00 PM
    Friday, November 1, 2013 7:03 PM
  • Does .net framework 4.5 make any better on CLR performance  for 64-bit process?

    SP


    • Edited by Apastambha Tuesday, November 5, 2013 12:15 PM
    Tuesday, November 5, 2013 12:14 PM
  • Yes, there are a ton of improvements in .NET 4.0.  .NET 4.0 is the first release since 2.0 that is a whole new CLR.

    See eg

    Garbage Collection

    The .NET Framework 4 provides background garbage collection. This feature replaces concurrent garbage collection in previous versions and provides better performance. For more information, see Fundamentals of Garbage Collection.

    The .NET Framework 4.5 includes new garbage collector enhancements for client and server apps

    David


    David http://blogs.msdn.com/b/dbrowne/

    Tuesday, November 5, 2013 3:38 PM
  • Wow! That looks cool about 4.5 improvements! Are there any benchmarks on CLR/GC performance (4.0 vs. 4.5)?

    SP

    Wednesday, November 6, 2013 4:48 PM
  • In a Windows 2008 x64 OS & .net framework 4.0 env, we are seeing "workstation" mode that triggers concurrent GC. Is there any advantage if we set this to "server" mode, where one GC does for all processors? We are not running GUI apps, but we are running web services.

    SP

    Wednesday, January 29, 2014 1:18 PM