Master Chief
Master Chief

Reputation: 2541

Disable Image caching in WP7

I am having a horrible time with the automatic image caching by WP7 platform.

I made a very simple app (I mean real simple). They have 2 images already added in solution as content of pix dimension 1280 x 2000 Here is XAML

<Grid x:Name="LayoutRoot" Background="Transparent" ManipulationCompleted="ImageHolder_ManipulationCompleted">
    <Image x:Name="ImageHolder" />
    <TextBlock x:Name="MemoryUsage" />
</Grid>

My .cs

   ImageHolder.Source = null;
        if (i % 2 == 0)
            ImageHolder.Source = new BitmapImage(new Uri("image002.jpg", UriKind.Relative));
        else
            ImageHolder.Source = new BitmapImage(new Uri("image001.jpg", UriKind.Relative));
        i++;

   MemoryUsage.Text = "Device Total Memory = " + (long)DeviceExtendedProperties.GetValue("DeviceTotalMemory") / (1024 * 1024)
            + "\nCurrent Memory Usage = " + (long)DeviceExtendedProperties.GetValue("ApplicationCurrentMemoryUsage") / (1024 * 1024)
            + "\nPeak Memory Usage = " + (long)DeviceExtendedProperties.GetValue("ApplicationPeakMemoryUsage") / (1024 * 1024);

Memory usage is very high is equal to the 2 images in raw bitmap size, though there should only be one such instance. Please help, I am in dire need.

Upvotes: 2

Views: 345

Answers (1)

Andras Csehi
Andras Csehi

Reputation: 4305

First of all resize your image to the correct size. There is no point to have such high resolution if the screen doesn't support it. Also make sure the build action for the image is "Content" otherwise all your images will be loaded to memory at start up. You might still see high memory usage because there is no garantee GC will dispose the image immediately but sooner or later it will.

Upvotes: 1

Related Questions