当前位置: 代码迷 >> Windows Mobile >> ListBox中填充多个WebBroswer罗致内存溢出
  详细解决方案

ListBox中填充多个WebBroswer罗致内存溢出

热度:58   发布时间:2016-04-25 07:17:09.0
ListBox中填充多个WebBroswer导致内存溢出
场景如下:
在一个ListBox中填充WebBroswer控件,WebBroswer控件展示的web页面每个页面大小大概为50K,ListBox的Item大小为100。Web页面内容由客户端通过HttpWebRequest获取,返回的结果集缓存到ObservableCollection中。在最极端的情况下,客户端ObservableCollection可能缓存了100个页面的数据。现在出现的问题是ListBox滑动的过程中可能会出现内存溢出错误,请各位达达指点迷津,谢谢。
另外,在测试中发现,如果客户端获取的web页面缓存到客户端而不显示到WebBroswer控件中,则不会出现内存溢出的情况(代码注释部分)。
<ListBox x:Name="itemcontrol" Grid.Row="0" ItemsSource="{Binding }">
            <ListBox.ItemTemplate>
                <DataTemplate >
                    <Border Tag="{Binding PageIndex}" Width="{Binding ElementName=this, Path=CWidth}" Height="{Binding ElementName=this,Path=CHeight}" BorderThickness="1,1,1,1" Margin="0,0,0,5">
                        <Grid Tag="{Binding PageIndex}">
                            <toolkit:GestureService.GestureListener>
                                <toolkit:GestureListener x:Name="_gridgesture" DoubleTap="_gridgesture_DoubleTap_1" DragDelta="_gridgesture_DragDelta_1" DragStarted="_gridgesture_DragStarted_1" DragCompleted="_gridgesture_DragCompleted_1" PinchStarted="GestureListener_PinchStarted_1" PinchDelta="GestureListener_PinchDelta_1"  PinchCompleted="GestureListener_PinchCompleted_1"/>
                            </toolkit:GestureService.GestureListener>
                            <Border Visibility="Visible" Background="Transparent">
                                <mycontrols:WebBroswerControl Tag="{Binding PageIndex}"  x:Name="content"  Background="Transparent">
                                    <!--PageContent="{Binding Path=PageContent}"-->
                                </mycontrols:WebBroswerControl>
                            </Border>
                            <Border Background="Transparent" Tag="{Binding PageIndex}">
                                <Grid VerticalAlignment="Center" HorizontalAlignment="Center" Width="{Binding ElementName=this, Path=CWidth}" Height="{Binding ElementName=this,Path=CHeight}">
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="45*"/>
                                        <RowDefinition Height="45*"/>
                                        <RowDefinition Height="10*"/>
                                    </Grid.RowDefinitions>

                                    <TextBlock Visibility="{Binding PageVisible,Converter={StaticResource _converter}}" Height="60"  VerticalAlignment="Bottom" TextAlignment="Center" HorizontalAlignment="Center" FontSize="30" Grid.Row="0" Foreground="#d3d3d3" Text="加载中,请稍后…">
  相关解决方案