C# 内存不足windows phone 8例外

C# 内存不足windows phone 8例外,c#,windows-phone-8-sdk,C#,Windows Phone 8 Sdk,我已经创建了一个动态透视图,其中数据通过一个列表绑定,在这个列表中,数据随机变化,几乎在列表中的100到150个条目之间。一切进展顺利,数据被添加到列表中,但当数据绑定时,应用程序意外终止,并显示内存不足异常 我的代码有点像这个xaml <Controls:Pivot x:Name="pvtDeals" Background="Gray" ItemsSource="{Binding CityItemList}" Grid.Row="1"> <Controls:Pivot.

我已经创建了一个动态透视图,其中数据通过一个列表绑定,在这个列表中,数据随机变化,几乎在列表中的100到150个条目之间。一切进展顺利,数据被添加到列表中,但当数据绑定时,应用程序意外终止,并显示内存不足异常

我的代码有点像这个xaml

<Controls:Pivot x:Name="pvtDeals" Background="Gray" ItemsSource="{Binding CityItemList}" Grid.Row="1">
   <Controls:Pivot.ItemTemplate>
       <DataTemplate>
           <Grid >
               <Grid.RowDefinitions>
                   <RowDefinition Height="200"/>
                   <RowDefinition Height="Auto"/>
                   <RowDefinition Height="*"/>
               </Grid.RowDefinitions>
               <Image x:Name="imgDeal" Tag="0" Source="{Binding ImageLink}" Stretch="Uniform" HorizontalAlignment="Stretch"  />
               <TextBlock Foreground="Red" Text="{Binding Title}" Grid.Row="1" TextWrapping="Wrap"/>
               <ScrollViewer Grid.Row="2">
                   <TextBlock Foreground="Black" Text="{Binding Description}" TextWrapping="Wrap" Grid.Row="2"/>
               </ScrollViewer>
           </Grid>
       </DataTemplate>
   </Controls:Pivot.ItemTemplate>
</Controls:Pivot>

cs代码

var xml = XDocument.Parse(e.Result); // from XML string, e.g.


// SaveDealInfoToIsolatedStorage(e.Result);

System.Text.RegularExpressions.Regex rx = new System.Text.RegularExpressions.Regex("<[^>]*>");

        var Channel = xml.Root.Elements("channel").ToList();
        var items = Channel[0].Elements("item").ToList();
        App.MainViewModel.CityItemList.Clear();

        foreach (var item in items)
        {
            App.MainViewModel.CityItemList.Add(new Model.CityItems
                {
                    Title = item.Element("title").Value,
                    Description = rx.Replace(item.Element("description").Value.Replace("\"", string.Empty), string.Empty),
                    ImageLink = item.Element("imageURL").Value,//image,
                    WebLink = item.Element("link").Value
                });

            System.Diagnostics.Debug.WriteLine(App.MainViewModel.CityItemList.Count.ToString());
        }
var xml=XDocument.Parse(e.Result);//来自XML字符串,例如。
//SaveDealInfoToIsolatedStorage(如结果);
System.Text.RegularExpressions.Regex rx=新的System.Text.RegularExpressions.Regex(“]*>”);
var Channel=xml.Root.Elements(“Channel”).ToList();
var items=Channel[0]。元素(“item”).ToList();
App.MainViewModel.CityItemList.Clear();
foreach(项目中的var项目)
{
App.MainViewModel.CityItemList.Add(新建模型.CityItems
{
标题=项目.元素(“标题”).值,
Description=rx.Replace(item.Element(“Description”).Value.Replace(“\”,string.Empty),string.Empty),
ImageLink=item.Element(“imageURL”).Value,//image,
WebLink=item.Element(“link”).Value
});
System.Diagnostics.Debug.WriteLine(App.MainViewModel.CityItemList.Count.ToString());
}

问题是什么?是什么原因造成的,如何避免,或者发生时如何处理?我认为您发布的代码不会泄漏任何内存,我怀疑泄漏可能在某个地方else@Theodoros是的,我的问题是什么导致了这种情况,然后如何避免和处理它。该代码在设备中大约70个条目运行良好,但同样失败n模拟器。高于70的条目在这两个方面都失败。