简体   繁体   English

列表框:WP8上的内存不足异常

[英]ListBox: Out Of Memory Exception on WP8

I have two ListBoxs in my pivot and each has an image. 我的透视图中有两个ListBox,每个都有一个图像。

<DataTemplate x:Key="PostsFieldItemTemplate" >
    ...
      <Image  Grid.Row="0" Margin="5" Width="100" Height="100" HorizontalAlignment="Left" Source="{Binding WImage}" Stretch="UniformToFill"/>
    ...
</DataTemplate> 

<DataTemplate x:Key="ItemTemplateListBoxAnimation">
    ...
    <Image Width="235" Height="210" Grid.Row="0" Source="{Binding tImage}" Stretch="UniformToFill"/>
    ...
</DataTemplate>

And i add url string to image in my code 我在代码中添加URL字符串到图像

PostsField.Items.Add(new ListPost(post.id, api.improveText(post.title), api.improveText(post.excerpt), post.attachments[0].url, api.improveDate(post.date)));

GridImages.Items.Add(new TempGrid(post.id, post.attachments[0].url, api.improveText(post.title), api.improveDate(post.date)));

Then i press on my button "LOAD MORE" and at some point I recieve exception (Out Of Memory). 然后,我按我的按钮“加载更多”,并在某个时候收到异常(内存不足)。 I commented out <Image Source="{Binding MyImage}"... /> in my ItemTemplates and all is ok.. 我在ItemTemplates中注释了<Image Source="{Binding MyImage}"... /> ,一切都OK。

Can you tell me please, what should i do to improve my Images ? 您能告诉我,我该怎么做才能改善我的图像?

there is a limit on memory usage for app here is the details. 应用程序的内存使用量有限制,详细信息在这里。 you can find detail here 你可以在这里找到细节

as you mentioned that you are loading images form API(web API I think). 正如您提到的,您正在从API(我认为是Web API)加载图像。 and showing them in list box on some button click and at some point out of memory exception is thrown. 并在单击某些按钮的列表框中显示它们,并在某些时候抛出内存不足异常。 now on low memory phone, an app can use upto 150MB of phone memory. 现在在低内存电话上,一个应用程序最多可以使用150MB的电话内存。 when your app exceeds that limit it throws this exception is thrown. 当您的应用超出该限制时,将引发此异常。 what you can do is to remove/dispose previously added images from listbox to release the memory and than add new Images. 您可以做的是从列表框中删除/处理以前添加的图像以释放内存,然后添加新图像。

You can check the memory limit available to your app by checking the ApplicationWorkingSetLimit value using the DeviceExtendedProperties.GetValue(String) method. 您可以通过使用DeviceExtendedProperties.GetValue(String)方法检查ApplicationWorkingSetLimit值来检查应用程序可用的内存限制。 For an example of how to do this see How to disable features in apps for lower-memory phones for Windows Phone 8 有关如何执行此操作的示例,请参阅如何为Windows Phone 8的低内存电话禁用应用程序中的功能

Hope this helps 希望这可以帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM