Symptoms
The IMA Service sometimes becomes unresponsive or crashes due to heap corruption.
Cause
Heap corruption results from application coding mistakes or corrupt external data.
Although various hotfixes exist, it is not always possible to identify which module (Citrix or non-Citrix) is responsible for heap corruption because the effects of heap corruption usually reveal themselves after some time.
Resolution
To detect heap corruption at the moment it occurs, enable additional runtime diagnostics (called full page heap). If this diagnostic is enabled, an application dump is generated.
First, download and install Debugging Tools for Windows from Microsoft to use the gflags utility:
Debugging Tools for Windows 32-bit version
Debugging Tools for Windows 64-bit version
Use the following syntax to enable full page heap:
gflags /p /enable ImaSrv.exe /full
— or —
gflags /i ImaSrv.exe +hpa
To verify that gflags has enabled page heap verification, use the following command:
gflags.exe /p
— or —
gflags /i ImaSrv.exe
The command displays:
ImaSrv.exe: page heap enabled with flags (full traces)
— or —
Current Registry Settings for ImaSrv.exe executable are 02000000
After the dump, full page heap is disabled to avoid performance degradation.
To disable full page heap, use the following command:
gflags /p /disable ImaSrv.exe
— or —
gflags /i ImaSrv.exe -hpa
To verify that full page heap is disabled, use the following command:
gflags.exe /p
— or —
gflags /i ImaSrv.exe
This command has the following output:
No application has page heap enabled
— or —
Current Registry Settings for ImaSrv.exe executable are 00000000
The same can be achieved using GUI interface of gflags.exe:

If you don’t want to install Debugging Tools for Windows, you can modify the registry directly:
Caution! This fix requires you to edit the registry. Using Registry Editor incorrectly can cause serious problems that may require you to reinstall your operating system. Citrix cannot guarantee that problems resulting from the incorrect use of Registry Editor can be solved. Use Registry Editor at your own risk. Be sure to back up the registry before you edit it.
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\ImaSrv.exe

You need to create two new REG_DWORD values under:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\<processname> as follows:
Name: GlobalFlag
Type: REG_DWORD
Value: 0x02000000
Name: PageHeapFlags
Type: REG_DWORD
Value: 0x00000003
Additional Information
If you need full page heap enabled for other applications, replace ImaSrv with your application name.
If you use NTSD as a default debugger to catch an application crash and you have a 64-bit system you need to be careful about which version of NTSD you use. For 32-bit processes (shown as *32 in Task Manager) you must set 32-bit NTSD as a default debugger:
http://www.dumpanalysis.org/blog/index.php/2006/10/23/ntsd-on-x64-windows/