WP8 Out of Memory error while loading Images

2019-02-23 22:04发布

问题:

I am working on Windows Phone 8 app.

I am working on Coverflow feature, i am trying to load 600 items but it always shows Out of Memory Error

Code:

<DataTemplate x:Key="DataTemplate1">
            <Grid VerticalAlignment="Center" HorizontalAlignment="Center">
                <Grid.RowDefinitions>
                    <RowDefinition/>
                </Grid.RowDefinitions>
                <Border Grid.Row="0" Height="400" Width="400" CornerRadius="30,30,30,30">
                    <Border.Background>
                        <ImageBrush ImageSource="Images/sample.png" />
                    </Border.Background>
                </Border>
                <Grid Grid.Row="0" HorizontalAlignment="Center" VerticalAlignment="Top">
                    <TextBlock HorizontalAlignment="Center" 
                               VerticalAlignment="Center"
                               Margin="5,20,5,5"
                               Foreground="#000000"
                               Text="{Binding Title}"/>
                </Grid>
                <Grid Grid.Row="0" HorizontalAlignment="Center" VerticalAlignment="Bottom">
                <TextBlock HorizontalAlignment="Center" 
                               VerticalAlignment="Center"
                               Margin="5,5,5,20"
                               Foreground="#000000"
                               Text="{Binding SubTitle}"/>
                </Grid>
            </Grid>
        </DataTemplate>

I have tried checking why its happening so,because each time it loads image with the below code

<Border Grid.Row="0" Height="400" Width="400" CornerRadius="30,30,30,30">
                        <Border.Background>
                            <ImageBrush ImageSource="Images/sample.png" />
                        </Border.Background>
                    </Border>

I tried removing Width and Height and it works but i want the image to bigger.

How can i fix this ?

回答1:

Here it's been discussed in detail. What you'll need to do is use Memory Profiling and periodically check which the memory Heap to see what's allocated when it shouldn't be.

How to debug running out of memory on Windows Phone