0

I noticed that my Xamarin.Forms app needs more and more memory when doing nothing. Now I used the Xamarin.Forms template project and profiled it on a iOS device (iPad):

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:local="clr-namespace:TestProfiler"
             x:Class="TestProfiler.MainPage">

    <StackLayout>
        <!-- Place new controls here -->
        <Label Text="Welcome to Xamarin.Forms!" 
           HorizontalOptions="Center"
           VerticalOptions="CenterAndExpand" />
    </StackLayout>

</ContentPage>

As you can see there is nothing, which would explain the memory increase, but the memory is increasing and increasing in the memory graph. Now I compared the two snapshots:

Comparing snapshots

System.RuntimeType, System.String and Xamarin.Forms.BindableProperty are having live objects. But I don't understand the sizes, because the graph increased from 42 MB to over 100 MB ...

Is the profiler wrong or am I misinterpreting the data? Why does the Xamarin.Forms app need more and more memory? I haven't touched it.

testing
  • 19,681
  • 50
  • 236
  • 417
  • add UWP project to the XF and [analyze here the memory](https://blogs.windows.com/windowsdeveloper/2015/10/07/optimizing-your-xaml-app-for-performance-10-by-10). Maybe it also shows up for Windows and the advanced tooling helps to diag the cause. – magicandre1981 Oct 08 '19 at 14:49
  • I tried to profile with Xcode's Instruments. Here the app stayed at 9.3 MB. Currently, I think it is an issue with the Xamarin profiler itself ... But your idea sounds interesting. – testing Oct 08 '19 at 15:06
  • Try to toggle the "Concurrent garbage collector" in the Project options, do you see a different graph? – Saamer Oct 08 '19 at 19:55
  • @magicandre1981: Now I tested the `Performance profiler` and the memory usage stayed relatively constant (from 35 MB in the beginning to about 34 MB after six minutes). – testing Oct 09 '19 at 09:31
  • 1
    @Saamer: It shows the same behavior. Climbing from 26 MB to 34 MB after nine minutes. But not nearly as much as the default garbage collector. – testing Oct 09 '19 at 09:32
  • Oh great. Problem solved? The place where garbage collection may not happen is while dealing with files and occasionally with images. You have to dispose those properly. – Saamer Oct 09 '19 at 12:38
  • @Saamer: my main question was, why does the memory goes up, when the app isn't allocating new resources? The concurrent garbage collector is still in experimental state - so I don't know if I should use it in production code. And the last one: Is the Xamarin profiler that useful to show me the real memory usage? – testing Oct 09 '19 at 12:42
  • I have no idea why you see this. I always profile UWP part of XF app and don't use Xamarin Profiler that much – magicandre1981 Oct 09 '19 at 13:36
  • @magicandre1981: your idea is basically good, but I haven't implemented everything for UWP and so I can't really debug my application this way. But the observation I made (aká my question) indicates that the profiler isn't that useful yet. – testing Oct 09 '19 at 13:44

0 Answers0