如何将 RAM 使用量保持在 90MB 以下? (特别是缩放图像)

发布于 2024-09-26 04:45:38 字数 770 浏览 4 评论 0原文

我正在开发一个适用于 WP7 的应用程序(适用于 Windows Phone RTM 和 WP 模拟器的 VS2010 Express),但现在我面临着与内存使用相关的大问题。 该应用程序本身有大约 12 个视图,其中一些视图与不同的数据一起重复使用。它是一个新闻阅读器,因此视图主要是列表框(图像缩略图、堆栈面板和文本块)。

第一个视图有一个包含 30 个项目的列表框。这需要大约 20MB 的 RAM,但当我在视图之间导航时,当前和峰值 RAM 使用量开始上升。峰值使用量约为 55MB,我认为还可以,但该应用程序有一个图库部分,在选择缩略图后,它会导航到另一个视图,该视图显示下载的图像(JPEG,1131px × 1647px,〜486KB),但最初适合屏幕。到目前为止一切都很好,但出于缩放目的,我使用 Laurent Bugnion 的多点触控行为问题是,当我放大图像时,内存使用量接近 90MB(就像我上次在最大缩放比例为 2.5 时测试的 87MB 一样)。

此外,在我导航视图后,当前的 RAM 使用量可能会永久达到并保持在 35MB,我相信这是由于设备缓存了一些东西。

那么,正如标题所说,我怎样才能避免如此巨大的内存使用呢?

编辑----
另外我想问一下,在我的应用程序中,人们是否可以从任何视图导航到几乎所有其他视图,并且在它们之间总是有一个页面转换动画(就像测试版工具中的电话列表应用程序模板的动画),可能会导致内存使用过多。

I'm developing an app for WP7 (VS2010 Express for Windows Phone RTM and WP Emulator), but now im facing a big problem related to memory usage.
The app itself has like 12 views, and some of them are reused with different data. It's a newsreader, so the views are mostly listboxes (image thumbnail, stackpanels and textblocks).

The first view has a listbox with 30 items. This takes about 20MB of RAM, but as i navigate between views the current and peak RAM usage start to rise. Well the peak usage it's around 55MB which i think is OK, but the app has a gallery section in which after selecting a thumbnail it navigates to another view which displays a downloaded image (JPEG, 1131px × 1647px, ~486KB) but initially fit to the screen. Until here all good, but for scaling purposes i'm using Laurent Bugnion's Multitouch Behavior and the problem is that when i zoom in the image, the memory usage gets near 90MB (like 87MB last time i tested with the maximum scale size at 2.5).

Also after i navigate the views the current ram usage may permantly reach and stay at 35MB, which i beleive is due to the device caching some things.

So, as the title says, how can i avoid such huge ram usage?

Edit----
Also i'd like to ask if the fact that in my app one can navigate from any view to almost every other and that in between there's always a page transition animation (like the one for the phone list application template in the beta tools), may be contributing to the excessive memory usage.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

魂归处 2024-10-03 04:45:38

一般来说,您希望图像尽可能小(尺寸和颜色深度,不一定是文件大小)。为了显示图像,设备必须将其解压缩为实际的位图,因此在这种情况下,您正在查看 1131x1647 像素的图像,假设为 16bpp,这意味着您有 3.7MB 的内存占用空间用于该图像,而不是486k 文件大小。

根据您的缩放/旋转,可能会有第二个复制缓冲区,因此您可以有效地将其加倍。按照这个速度,很快就可以达到 90MB。我当然会尝试下载较小的图像文件或尝试在本地调整它们的大小,然后使用调整大小的图像。

Generally speaking you want to keep images as small as feasible (in dimensions and color depth, not necessarily file size). In order to display an image, the device must decompress it to an actual Bitmap, so in this case you're looking at a 1131x1647pixel image, let's say at 16bpp, means that you have a 3.7MB memory footprint for the image, not the 486k file size.

Depending on your zoom/rotate, there may be a second copy buffer, so you can effectively double that. It doesn't take long at that rate to get to 90MB. I'd certainly try either download smaller image files or try resizing them locally and then using the resized image.

安人多梦 2024-10-03 04:45:38

好吧,也许我应该研究一下 DeepZoom (但当我第一次读到它时,我认为它是为了在不同尺寸的相同图像上使用它,就像卫星视图中的谷歌地图一样),但昨天我通过在我的内部使用网络浏览器解决了这个问题视图,所以如果在我之前:

<Image x:Name="imgPlaceHolder" delay:LowProfileImageLoader.UriSource="{Binding Path=ActualImageSource}" MaxHeight="800"
               MaxWidth="480" >
            <interac:Interaction.Behaviors >
                <tbeh:MultiTouchBehavior x:Name="ImageMTB" IsScaleEnabled="True"
                                                 MinimumScale="0.4"
                                                 MaximumScale="2.5"
                                                 IsRotateEnabled="False"
                                                 IsDebugModeActive="False"
                                                 IsTranslateXEnabled="True"
                                                 IsTranslateYEnabled="True"

                                     >

                </tbeh:MultiTouchBehavior>
            </interac:Interaction.Behaviors>
        </Image>

我将其更改为:

<phone:WebBrowser Source="{Binding Path=ActualImageSource}" x:Name="wbbigimage"  />

它使用更少的内存并且可以毫无问题地处理缩放。

在检查这个之前,我会等一下有人有更好的解决方案。

Well maybe i should look into deepzoom (but when i first read about it, i thought it was for using it with the same image at different sizes, like google maps in satellite view), but yesterday i solved it by using a webbrowser inside my view, so if before i had:

<Image x:Name="imgPlaceHolder" delay:LowProfileImageLoader.UriSource="{Binding Path=ActualImageSource}" MaxHeight="800"
               MaxWidth="480" >
            <interac:Interaction.Behaviors >
                <tbeh:MultiTouchBehavior x:Name="ImageMTB" IsScaleEnabled="True"
                                                 MinimumScale="0.4"
                                                 MaximumScale="2.5"
                                                 IsRotateEnabled="False"
                                                 IsDebugModeActive="False"
                                                 IsTranslateXEnabled="True"
                                                 IsTranslateYEnabled="True"

                                     >

                </tbeh:MultiTouchBehavior>
            </interac:Interaction.Behaviors>
        </Image>

I changed that to:

<phone:WebBrowser Source="{Binding Path=ActualImageSource}" x:Name="wbbigimage"  />

It uses less memory and takes care of the zoom with no problems.

I'll wait a bit for someone with a better solution before checking this one.

抽个烟儿 2024-10-03 04:45:38

有几点需要注意。首先,确保清除 onNavigedFrom 方法期间在页面上使用的所有列表或图像。 WP7处理图像的方式很“有趣”。我发现有帮助的一件事是在页面未显示时取消任何全景控件的背景。

至于您的具体问题,您是否考虑过使用 MultiScaleImage(深度缩放)来减少内存?

http://msdn.microsoft。 com/en-us/library/system.windows.controls.multiscaleimage(VS.95).aspx

A couple of things to note. First, make sure that you are clearing out any lists or images that you are using on pages durring the onNavigatedFrom method. The way WP7 Deals with images is "interesting". One of the things I have found to help is to null out the background of any panorama controls when the page is not being displayed.

As for your specific issue, have you considered using a MultiScaleImage (Deep Zoom) to cut down on memory?

http://msdn.microsoft.com/en-us/library/system.windows.controls.multiscaleimage(VS.95).aspx

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文