Heap Corruption


  • Hello.

    I have constructed a Windows Phone application under and lately I am getting some very strange crash reports. A lot of them have something like the following:

    "Frame    Image                            Function                                                                                                                                    Offset        
    0        heap_corruption                  heap_corruption                                                                                                                             0x00000000"

    Does anybody know what this may come from? I have searched hours in the internet and the only thing that I found are some few articles saying that such thing can happen if you use DispatcherTimers and you do not unregister their event handlers.

    Could this also occur by using the Geolocator class in WP8? I mean is it possible that I might have such errors if I don't remove the listener on the StatusChanged event (I am only removing it on the PositionChanged - forgot to remove it from the StatusChanged).

    I have also downloaded the minidump files from the crash reports and tried to open them on Visual Studio. For sure, I don't know how to work with them but there are some few weird things happening (I think).

    1) The process name is 'Taskhost.exe'. This is not the application executable and it seems that it is a file from the Windows Phone O/S.

    2) Visual Studio also reports me (while loading the symbols) that 'No matching binary found'. I don't know if that is normal.

    3) After loading the symbols it displays me: 'Debugging information for TaskHost.exe can not be found or does not match. No matching binary found'. Should I also worry about that?

    4) When I continue debugging I get the following error:

    Unhandled exception at 0x77761ECF (KERNELBASE.dll) in minidump.mdmp: 0xE0434352 (parameters: 0x80131500, 0x00000000, 0x00000000, 0x00000000, 0x70DE0000).

    All these are quite strange to me and I can't find any good web site to read on how to find my errors from the minidump files. Does anybody know of a good one (for WP8 please) or can help me somehow?

    Thank you very much.

    Efthymios Kalyviotis

    Tuesday, January 21, 2014 1:05 AM

All replies

  • This issue may require a support case so we can do a detailed dump analysis to figure out the root cause.

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Tuesday, January 21, 2014 2:12 PM
  • Any idea on how to proceed?

    Do I need to make a support incident?

    Can I somehow detect the error myself?

    Tuesday, January 21, 2014 2:39 PM
  • FYI: Taskhost.exe is the host for managed applications.  If you look in your XAP or at the output you will notice that your 'application' compiles to a DLL.

    IIRC, We don't publish symbols for the internal Windows Phone components, like Taskhost.exe, so I'm not sure how useful that dump file will be to you...

      In my experience, even with symbols, heap corruption is difficult to debug from a dump file because the code which actually causes the corruption often executes and exits long before the resulting crash... the code executing when the exception occurs is often unrelated.

      The only recognizable value I see in what you posted is the exception parameter: 0x80131500, which is just the base exception value from the .Net core libraries, i.e. CORE_E_EXCEPTION.  (...probably thrown by the function: 'heap_corruption'.)

      I would first look for any operations which manipulate binary data and calls to 3rd party libraries implemented in native code.


    Tuesday, January 21, 2014 4:25 PM
  • Hello Eric.

    Are there any kind of tools where I can see if there is any heap illegal operation while debugging the application (via Visual Studio) on my phone or emulator?

    One of my obvious problems is that the error does not pop up on my side but on the clients side. If it was popping up on my side then I would probably remove line by line plenty of code until I see it fixed. The application crash especially on low memory devices from what I have heard from my clients. This is a kind of logical to me since the memory is limited there and a (perhaps) non managed application doing some illegal memory operation has much more possibilities to write in wrong address space in such low memory devices.

    If there are any kind of tools for heap inspection or I can somehow limit the available memory for my application on a device (eg. create a 64MB RAM memory emulator and even less) then I might be able to reproduce such problems on my side and at least get an idea after which executed function the problems popup. I need to somehow isolate the problem and play with it until I really find it (and find the solution of it).

    Are you aware of anything that could help me?

    Thank you very much.

    Tuesday, January 21, 2014 5:22 PM
  • I would expect the debugger to be able to break for this exception ... In the Exceptions dialog (menu: "Debug"->"Exceptions...") you can configure the debugger to break when a specific exception is thrown.  (In this case probably : System.Runtime.InteropServices)

    However, the CPU architecture on the Emulator is different from the device so it may not reproduce the problem or the problem may show up in a different way... like simple data corruption rather than heap corruption.

    Other than that you could try running a Code Analysis on your project and evaluate the warnings / suggestions.


    Thursday, January 23, 2014 6:00 PM
  • Hello.

    That problem seems to be driving me crazy. I have tried a Code Analysis and here are some of my results:

    1) CA2202 Do not dispose objects multiple times Object 'stream' can be disposed more than once in method 'XMLStorage.LoadClass(ref object)'. To avoid generating a System.ObjectDisposedException you should not call Dispose more than one time on an object.: Lines: 61 HeapCorruption XMLStorage.cs 61

    This results in 4 different places of the application. Code like the following:

    IsolatedStorageFileStream stream = storage.OpenFile(FileName, FileMode.Open);
                    XmlSerializer xml = new XmlSerializer(obj.GetType());
                            obj = xml.Deserialize(stream);

    and the next one

    using (var store = IsolatedStorageFile.GetUserStoreForApplication())
                    //var streamIn = store.OpenFile(filename, FileMode.Open);
                    using (var streamIn = store.OpenFile(name + ".zip", FileMode.Open))
                        using (var zipStreamOut = new GZipInputStream(streamIn))
                            using (var fileStreamOut = store.CreateFile(name + ".txt"))

    would produce such warning. Although I have done extreme tests of both in a test application, both on emulator and on a real test device, not any kind of Heap corruption did pop up apart from some 'Out of memory' exceptions (which was normal). 

    2) CA1009 Declare event handlers correctly Declare the first parameter of 'MediaPlayerControl.ClosePage' as an object named 'sender'. PedometerWP8 MediaPlayerControl.xaml.cs 25

    Such warnings were popped up by code like the following:

            public delegate void ClosePage();
            public event ClosePage closePage;

    This doesn't seem again of being capable of creating a heap corruption, although to be sure I have corrected all the above errors (in both cases).

    3) The third and most interesting warning that worried me a bit was the following:

    CA1001 Types that own disposable fields should be disposable Implement IDisposable on 'MainMenu' because it creates members of the following IDisposable types: 'WizardHelper'. If 'MainMenu' has previously shipped, adding new members that implement IDisposable to this type is considered a breaking change to existing consumers. PedometerWP8 MainMenu.xaml.cs 21

    That kind of warning is a bit tricky. I have a member variable in some of my classes that its class is implemented using IDisposable. I have done it because I had to ensure that somehow some of my managed resources are immediately being released by the GC (Garbage Collector) when I need it (I had some .net errors with the navigation of my app). In any way, I am not using any kind of unmanaged resources inside the class that implements IDisposable which means that whichever way, GC should free the resources when needed (even if I don't manually call the Dispose mechanism). Basically it shouldn't be producing any kind of heap corruption in my opinion. If I was using any unmanaged resources there, then yes, I should be worrying 'a lot'.

    Of course, the first two types of warnings have been fixed. About the third (with the IDisposable), I will try to find a workaround to fix such warnings. Both three types of warnings don't seem to be able to create any heap corruption.

    Do you think that I should be better create a support incident to a Microsoft technician in order to see if we can find out where the problem lies? I started believing that this might be a kind of an O/S bug.


    Sunday, January 26, 2014 5:18 PM
  • Anyone else having any suggestion for my above problem?

    I am really desperate.

    Anyone knows if SharpZipLib for Windows phone can be able to produce 'heap corruption' issues?

    I am also using some Telerik's and ComponentOne's assemblies.

    Thank you very much.


    Tuesday, February 25, 2014 7:35 PM
  • IMO it's unlikely that the dispose methods you are using, whilst incorrectly, wouldn't normally cause a heap corruption. It's more likely to be in a component that is written in C++, be that in a 3rd party app or a bug in the underlying platform code. Can you repro the problem?

    Tuesday, February 25, 2014 8:57 PM
  • Hi.

    No. My main problem is that unfortunately I can not reproduce the problem either on emulator or a real device but some of my users complain via email (eg. while trying to use the camera app and my app runs in the background). If I could have some tools somehow to be able to reproduce it or some tools that can report me of possible heap problems while debugging then I could probably isolate the problem area of the code and try to fix it. I really don't know if there are tools that can inspect the heap or other things and let me know if something is going wrong.

    Any idea?

    Tuesday, February 25, 2014 9:38 PM
  • What do you mean by 'my app runs in the background'?

    Tuesday, February 25, 2014 10:59 PM
  • Actually it is a GPS tracker application. So the application is able to work in the background.
    Wednesday, February 26, 2014 2:21 PM
  • Without a repro it's going to be difficult to prove. But I would start isolating the code by logging and removing/stubbing out components.

    Wednesday, February 26, 2014 2:55 PM
  • I can not reproduce the problem on the emulator. Any kind of tool that can tell me that there might be any kind of corruption in the memory?
    Wednesday, February 26, 2014 3:20 PM