Not sure what the best way to report something like this is, but I thought I'd post it here in case anyone else runs into it.
If you use the Frame element (Android only) and the size of the frame (i.e. the size of its content) changes, you'll end up with a memory leak and a crash very quickly. It seems that the FrameRenderer creates a new bitmap every time the size changes, but never disposes of the previous one. This means that you'll quickly allocate several megabytes for each small change.; the implementation is sub-optimal just to set the background color and draw a border. The issue is easy to reproduce:
XAML:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="FrameMemoryLeak.MainPage">
<StackLayout Orientation="Vertical">
<Frame BackgroundColor="White" HasShadow="True" OutlineColor="Black">
<Label x:Name="SampleLabel" VerticalOptions="Center" HorizontalOptions="Center" />
</Frame>
<Button x:Name="UpdateButton" Text="Update size"/>
</StackLayout>
</ContentPage>
C#:
public partial class MainPage : ContentPage
{
private int clickCount;
public MainPage()
{
InitializeComponent();
Button button = this.UpdateButton;
button.Clicked += (sender, args) =>
{
this.SampleLabel.Text += String.Format("Click count: {0}\n", ++clickCount);
};
}
}
As a side note, the Frame element does not render a shadow on Android. Neither of these issues exists on iOS.
//Tomi B.