2

Here is my code:

    public sealed partial class MainPage : Page
{
    InkCanvas[] arrInkCanvas = null;
    public MainPage()
    {
        this.InitializeComponent();

        int i = 0;

        arrInkCanvas = new InkCanvas[1000];
        try
        {
            for (i = 0; i < 1000; i++)
            {                    
                arrInkCanvas[i] = new InkCanvas();
            }
        }
        catch (Exception ex)
        {

        }
    }
}

When i run this code in WPF app there's no problem , but in UWP it throws exception : "Insufficient memory to continue the execution of the program."

Is it bugs or something can anyone tells me ?

Thanks.

meobeo173
  • 617
  • 1
  • 7
  • 20

2 Answers2

2

Windows OS will balance the memory located to the application based on RAM and OS configuration. You can check your app's memory configuration by MemoryManager (just as cFrozenDeath said) in following way:

 public MainPage()
 {
     this.InitializeComponent();

     var AppUsageLevel = MemoryManager.AppMemoryUsageLevel;
     var AppMemoryLimit = MemoryManager.AppMemoryUsageLimit;
  }

From my test, your app does run out of memory. You can do a simple test: In the for loop each time you new InkCanvas(), you can call MemoryManager.AppMemoryUsage and compare it with the MemoryManager.AppMemoryUsageLimit.

Could you let me know if you have any specific reason for creating UIElment in such a way? Win10 1.586 does provide a new API, TrySetAppMemoryUsageLimit, to set the app's memory limitation. However, based on internal discussion, this API only works for very limited scenario right now, such as VOIP application on mobile device. And the sample code and document for this API are not quite ready.

Fangfang Wu - MSFT
  • 1,062
  • 6
  • 7
0

Looking into it, there is another post which looks similar, which suggests the limit might be at 128... which could be a limitation "by design"

If that is consistent - I have not tried it - why not creating a InkCanvas pool and reusing the InkCanvas once they are not in use? Unless you need them concurrently... Also that would add speed as you would avoid recreating the inkcanvas and just reuse them.

So far, the code could remain consistent and you can enlarge the pool when the issue/limitation is fixed..

Moumit
  • 8,314
  • 9
  • 55
  • 59