MobileMapPackage.LocatorTask.SuggestAsync fails with "Out of memory: bad allocation" error

426
1
Jump to solution
07-05-2021 05:06 AM
ChrisvanRenen
New Contributor

I have implemented an Address Search into a .NET 5 WPF application using the Esri.ArcGISRuntime.WPF SDK (version 100.11.2). On each key stroke in a textbox, I call the MobileMapPackage.LocatorTask.SuggestAsync method and return the results as an AutoSuggest type of dropdown under the textbox. This works 100% when testing locally by just running the WPF application via Visual Studio (VS 2019) debugger. The suggestions come back super fast and there are no errors.

We then package this WPF Application using a Windows Application Packaging Project to produce a MSIX file (targeting the x86 platform). When I just extract the contents of the MSIX (as it's just an archive), and then run the extracted exe for my application, the search is extremely slow (taking between 3-10 seconds per letter typed. I also get a lot of these errors for some of the calls to the method (seems to be at random times):

Esri.ArcGISRuntime.ArcGISRuntimeException: Out of memory: bad allocation
at Esri.ArcGISRuntime.ArcGISException.HandleCoreError(CoreError error, Boolean throwException)
at RuntimeCoreNet.GeneratedWrappers.Interop.CheckError(IntPtr errorHandle, Boolean throwOnFailure, GCHandle wrapperHandle)
at RuntimeCoreNet.GeneratedWrappers.CoreTask.Get()
at Esri.ArcGISRuntime.Internal.CoreTaskExtensions.TaskCompletedCallbackHandler`1.OnCompleted(Object sender, EventArgs e)
--- End of stack trace from previous location ---
at Esri.ArcGISRuntime.Internal.CoreTaskExtensions.TaskCompletedCallbackHandler`1.CreateInternal(CoreTask task, CancellationToken cancellationToken)

The errors and slow responses happen if we install the MSIX as well. Not really sure what could be causing this and any help would be greatly appreciated.

Update:

This is some of the errors and timings I'm seeing for just the SuggestAsync call to execute:

2021-07-05 13:34:40.074 +02:00 [ERR] AddressSearchDialogViewModel -> Could not find addresses for 8
Esri.ArcGISRuntime.ArcGISRuntimeException: Out of memory: bad allocation
at Esri.ArcGISRuntime.ArcGISException.HandleCoreError(CoreError error, Boolean throwException)
at RuntimeCoreNet.GeneratedWrappers.Interop.CheckError(IntPtr errorHandle, Boolean throwOnFailure, GCHandle wrapperHandle)
at RuntimeCoreNet.GeneratedWrappers.CoreTask.Get()
at Esri.ArcGISRuntime.Internal.CoreTaskExtensions.TaskCompletedCallbackHandler`1.OnCompleted(Object sender, EventArgs e)
--- End of stack trace from previous location ---
at Esri.ArcGISRuntime.Internal.CoreTaskExtensions.TaskCompletedCallbackHandler`1.CreateInternal(CoreTask task, CancellationToken cancellationToken)
at AddressSearchDialogViewModel.SearchForAddresses(String searchText)
2021-07-05 13:34:40.420 +02:00 [INF] AddressSearchDialogViewModel -> SuggestAsync for '8 d' took 3010.1267ms for 2 results.
2021-07-05 13:34:40.623 +02:00 [INF] AddressSearchDialogViewModel -> SuggestAsync for '8 de' took 3172.6972ms for 0 results.
2021-07-05 13:34:40.703 +02:00 [INF] AddressSearchDialogViewModel -> SuggestAsync for '8 del' took 3154.9665ms for 2 results.
2021-07-05 13:34:41.253 +02:00 [INF] AddressSearchDialogViewModel -> SuggestAsync for '8 deli' took 3520.1223ms for 5 results.

0 Kudos
1 Solution

Accepted Solutions
ChrisvanRenen
New Contributor

So after a lot of investigation, it turns out that building the WPF application and targeting the x86 platform (32bit) was the issue. We started getting more and more memory related issues and decided to explicitly target the x64 platform (64bit) to utilize the increased allocation of memory to the .NET process... and this solved all the memory issues. We no longer get the "bad allocation" SDK errors.

I hope this helps anyone else that struggles with these errors

View solution in original post

0 Kudos
1 Reply
ChrisvanRenen
New Contributor

So after a lot of investigation, it turns out that building the WPF application and targeting the x86 platform (32bit) was the issue. We started getting more and more memory related issues and decided to explicitly target the x64 platform (64bit) to utilize the increased allocation of memory to the .NET process... and this solved all the memory issues. We no longer get the "bad allocation" SDK errors.

I hope this helps anyone else that struggles with these errors

View solution in original post

0 Kudos