Freezing on iOS Net 9 Maui ? #743

Open
opened 2026-01-29 14:44:34 +00:00 by claunia · 7 comments
Owner

Originally created by @EricLVertiGIS on GitHub (Jun 22, 2025).

Hi, we have a .NET Maui application. Since upgrading to .NET 9, our app freezes on iOS when our custom Markdown view reappears (ie. filtered then unfiltered inside a CollectionView). At first I thought it might be a Maui issue, but after investigation, the only line that causes this behavior is :
Markdig.Markdown.Parse(Markdown)

Our issue behaves quite similar to https://github.com/xoofx/markdig/issues/585. It works fine in Debug Mode, but on Release Mode (iOS only), the freeze happens. I saw that a fix was released in https://github.com/xoofx/markdig/pull/600/files, but updating to the newest version didn't resolve the issue.

.NET 9 Maui added changes to trimming code, so that could be a factor. The Markdown view is garbaged collected then recreated each time it disappears / reappears, but Parse is static so that shouldn't be a problem.

Could the team please look into this ? Thank you

Originally created by @EricLVertiGIS on GitHub (Jun 22, 2025). Hi, we have a .NET Maui application. Since upgrading to .NET 9, our app freezes on iOS when our custom Markdown view reappears (ie. filtered then unfiltered inside a CollectionView). At first I thought it might be a Maui issue, but after investigation, the only line that causes this behavior is : `Markdig.Markdown.Parse(Markdown)` Our issue behaves quite similar to https://github.com/xoofx/markdig/issues/585. It works fine in Debug Mode, but on Release Mode (iOS only), the freeze happens. I saw that a fix was released in https://github.com/xoofx/markdig/pull/600/files, but updating to the newest version didn't resolve the issue. .NET 9 Maui added changes to trimming code, so that could be a factor. The Markdown view is garbaged collected then recreated each time it disappears / reappears, but `Parse` is static so that shouldn't be a problem. Could the team please look into this ? Thank you
claunia added the question label 2026-01-29 14:44:34 +00:00
Author
Owner

@EricLVertiGIS commented on GitHub (Jun 23, 2025):

Actually it seems our issue might be with the way newline is encoded. @xoofx What is Markdig's preferred / supported way to do line breaks ? Does it support double space, '', what about '\n' ?

@EricLVertiGIS commented on GitHub (Jun 23, 2025): Actually it seems our issue might be with the way newline is encoded. @xoofx What is Markdig's preferred / supported way to do line breaks ? Does it support double space, '\', what about '\n' ?
Author
Owner

@MihaZupan commented on GitHub (Jun 23, 2025):

Markdig treats "\r", "\n", or "\r\n" pretty much the same. Hard line breaks do support double spaces before a new line.

I don't see how that's related to "freezing" in release?

@MihaZupan commented on GitHub (Jun 23, 2025): Markdig treats `"\r"`, `"\n"`, or `"\r\n"` pretty much the same. Hard line breaks do support double spaces before a new line. I don't see how that's related to "freezing" in release?
Author
Owner

@EricLVertiGIS commented on GitHub (Jun 23, 2025):

@MihaZupan Our Markdown code calls Markdig.Markdown.Parse(Markdown) and then creates the views to display. If I comment out the view creation, just the parse alone causes the freeze on iOS release.

The markdown being passed in was:
"# Basic info\n**Trap Type:** Hawaii \\\n**Last Inspected:** Hawaii \\\n**Last Relocated:** Hawaii \\\n\n\n## Age groups \\\nUnder 5: 78163 \\\n_AGE_5_17:_ 217604 \\\n_AGE_18_21:_ 65456 \\\n*AGE_22_29:* 133437 \\\n*AGE_30_39:* 183094 \\\n**AGE_40_49:** 185646 \\\n**AGE_50_64:** 187536 \\\n*AGE_65_UP:* 160601"

This freezes. I then tried hard coding some simpler markdown and it worked fine. So something about this string is causing issues.

Sorry to bring up such a niche & complicated issue 😓

@EricLVertiGIS commented on GitHub (Jun 23, 2025): @MihaZupan Our Markdown code calls `Markdig.Markdown.Parse(Markdown)` and then creates the views to display. If I comment out the view creation, just the parse alone causes the freeze on iOS release. The markdown being passed in was: `"# Basic info\n**Trap Type:** Hawaii \\\n**Last Inspected:** Hawaii \\\n**Last Relocated:** Hawaii \\\n\n\n## Age groups \\\nUnder 5: 78163 \\\n_AGE_5_17:_ 217604 \\\n_AGE_18_21:_ 65456 \\\n*AGE_22_29:* 133437 \\\n*AGE_30_39:* 183094 \\\n**AGE_40_49:** 185646 \\\n**AGE_50_64:** 187536 \\\n*AGE_65_UP:* 160601"` This freezes. I then tried hard coding some simpler markdown and it worked fine. So something about this string is causing issues. Sorry to bring up such a niche & complicated issue 😓
Author
Owner

@EricLVertiGIS commented on GitHub (Jun 23, 2025):

We have CollectionView where each item is one MarkdownView. Each MarkdownView calls parse to render its markdown. It seems the parsing becomes more and more stable the shorter the markdown string is. I couldn't find a particular sequence that was problematic.

I'm unfamiliar with how CollectionView is implemented on iOS, but I imagine its rendering the views in parallel. Maybe when many complicated parses are happening in parallel, it ends up in a deadlock some how ?

@EricLVertiGIS commented on GitHub (Jun 23, 2025): We have CollectionView where each item is one MarkdownView. Each MarkdownView calls parse to render its markdown. It seems the parsing becomes more and more stable the shorter the markdown string is. I couldn't find a particular sequence that was problematic. I'm unfamiliar with how CollectionView is implemented on iOS, but I imagine its rendering the views in parallel. Maybe when many complicated parses are happening in parallel, it ends up in a deadlock some how ?
Author
Owner

@MihaZupan commented on GitHub (Jun 23, 2025):

I doubt anything in Markdig on its own could lead to a deadlock.

If it's never happening in Debug but reliably on Release that sounds more like a possible issue in the underlying runtime, e.g. maybe a different manifestation of #873.

Does the issue reproduce on a nightly build of .NET 10 main and MAUI?
https://github.com/dotnet/dotnet/blob/main/docs/builds-table.md
https://github.com/dotnet/maui/wiki/Nightly-Builds

@MihaZupan commented on GitHub (Jun 23, 2025): I doubt anything in Markdig on its own could lead to a deadlock. If it's never happening in Debug but reliably on Release that sounds more like a possible issue in the underlying runtime, e.g. maybe a different manifestation of #873. Does the issue reproduce on a nightly build of .NET 10 `main` and MAUI? https://github.com/dotnet/dotnet/blob/main/docs/builds-table.md https://github.com/dotnet/maui/wiki/Nightly-Builds
Author
Owner

@EricLVertiGIS commented on GitHub (Jun 24, 2025):

@MihaZupan Thank you, #873 does share similarities with to our issue. I saw that there is a PR for it https://github.com/dotnet/runtime/pull/116069 but couldn't find it in the dotnet/runtime release notes. Maybe 9.0.7 will releases the fixes.

Like #873, once we hit some sort of threshold, Parse freezes. If I make the markdown string shorter, it takes more calls of Parse to get the freeze. If I make the markdown string longer, it takes less calls of Parse to reach the freeze. Unlike #873, our threshold is based on the cumulative length of the markdown strings rather than the the number of calls. Also different from #873 is our app freezes instead of crashes (on iOS I think exceptions would just crash).

I'll retry once 9.0.7 releases and see if that fixes thing. I'll update this if I find anything new in the meantime.

@EricLVertiGIS commented on GitHub (Jun 24, 2025): @MihaZupan Thank you, #873 does share similarities with to our issue. I saw that there is a PR for it https://github.com/dotnet/runtime/pull/116069 but couldn't find it in the dotnet/runtime release notes. Maybe 9.0.7 will releases the fixes. Like #873, once we hit some sort of threshold, `Parse` freezes. If I make the markdown string shorter, it takes more calls of `Parse` to get the freeze. If I make the markdown string longer, it takes less calls of `Parse` to reach the freeze. Unlike #873, our threshold is based on the cumulative length of the markdown strings rather than the the number of calls. Also different from #873 is our app freezes instead of crashes (on iOS I think exceptions would just crash). I'll retry once 9.0.7 releases and see if that fixes thing. I'll update this if I find anything new in the meantime.
Author
Owner

@EricLVertiGIS commented on GitHub (Jul 22, 2025):

Hi @MihaZupan, I retested this with Maui 9.0.90 and .NET SDK 9.0.7, and Markdig 0.41.3, the issue still reproduces. It seems like it just crashes/freezes once Mardown.Parse is called many times. I created a simple repro. It's the base .NET Maui template. In the MainPage constructor, I added:

var data = "# Basic info\n**Trap Type:** Hawaii \\\n**Last Inspected:** Hawaii \\\n**Last Relocated:** Hawaii \\\n\n\n## Age groups \\\nUnder 5: 78163 \\\n_AGE_5_17:_ 217604 \\\n_AGE_18_21:_ 65456 \\\n*AGE_22_29:* 133437 \\\n*AGE_30_39:* 183094 \\\n**AGE_40_49:** 185646 \\\n**AGE_50_64:** 187536 \\\n*AGE_65_UP:* 160601";

for (int i = 0; i < 200; i++)
{

    var _ = Markdig.Markdown.Parse(data);
}

On iPhone 11, iOS 18.5. It runs fine in debug mode. But on release mode (or no debugger attached), the app will crash.

Attached Repro Demo: MarkdigiOSFreeze.zip

@EricLVertiGIS commented on GitHub (Jul 22, 2025): Hi @MihaZupan, I retested this with Maui 9.0.90 and .NET SDK 9.0.7, and Markdig 0.41.3, the issue still reproduces. It seems like it just crashes/freezes once `Mardown.Parse` is called many times. I created a simple repro. It's the base .NET Maui template. In the `MainPage` constructor, I added: ``` var data = "# Basic info\n**Trap Type:** Hawaii \\\n**Last Inspected:** Hawaii \\\n**Last Relocated:** Hawaii \\\n\n\n## Age groups \\\nUnder 5: 78163 \\\n_AGE_5_17:_ 217604 \\\n_AGE_18_21:_ 65456 \\\n*AGE_22_29:* 133437 \\\n*AGE_30_39:* 183094 \\\n**AGE_40_49:** 185646 \\\n**AGE_50_64:** 187536 \\\n*AGE_65_UP:* 160601"; for (int i = 0; i < 200; i++) { var _ = Markdig.Markdown.Parse(data); } ``` On iPhone 11, iOS 18.5. It runs fine in debug mode. But on release mode (or no debugger attached), the app will crash. Attached Repro Demo: [MarkdigiOSFreeze.zip](https://github.com/user-attachments/files/21355872/MarkdigiOSFreeze.zip)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/markdig#743