Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5930659
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T14:35:05+00:00 2026-05-22T14:35:05+00:00

Something is holding on to the images in my Silverlight application. This is a

  • 0

Something is holding on to the images in my Silverlight application. This is a problem because this is a catalog application with a lot of images that the user can browse through. If the user browses through every library provided the application will run out of memory and crash. I know it is a problem with images because if I disable images the private working set never exceeds 170 MB. I have a user control (DownloadImage) that shows a progress bar while the image is downloading. It is the only thing in my code that is referencing the BitmapImage objects. I ran a profiler (ANTS Memory Profiler 7.0 — good product, just giving them props) and it showed that all of the BitmapImage instances are being properly collected. As are all instances of DownloadImage controls.

Here is the code behind of DownloadImage:

    public partial class DownloadImage : UserControl
    {
        public static readonly DependencyProperty SourceProperty = DependencyProperty.RegisterAttached("Source", typeof(Uri), typeof(DownloadImage), new PropertyMetadata(null, OnSourcePropertyChanged));

        /// <summary>
        /// Default C'tor
        /// </summary>
        public DownloadImage()
        {
            InitializeComponent();
        }

        /// <summary>
        /// D'tor
        /// </summary>
        ~DownloadImage()
        {
        }

        /// <summary>
        /// Source - Image source.
        /// </summary>
        public Uri Source
        {
            get { return (Uri)GetValue(SourceProperty); }
            set { SetValue(SourceProperty, value); }
        }

        /// <summary>
        /// Initialize this DownloadImage with the given <see cref="BitmapImage"/> (<paramref name="a_bitmapImage"/>).
        /// </summary>
        /// <param name="a_bitmapImage">Given <see cref="BitmapImage"/>.</param>
        public void Create(BitmapImage a_bitmapImage)
        {
            _noImage.Visibility = Visibility.Collapsed;

            _image.Source = a_bitmapImage;
        }

        /// <summary>
        /// Initialize this DownloadImage with the given image source <see cref="Uri"/> (<paramref name="a_imageSource"/>).
        /// </summary>
        /// <param name="a_imageSource">Given image source <see cref="Uri"/>.</param>
        public void Create(Uri a_imageSource)
        {
            _noImage.Visibility = Visibility.Collapsed;

            BitmapImage bitmapImage = new BitmapImage();
            bitmapImage.CreateOptions = BitmapCreateOptions.DelayCreation | BitmapCreateOptions.IgnoreImageCache;
            bitmapImage.DownloadProgress += new EventHandler<DownloadProgressEventArgs>(OnDownloadProgress);
            bitmapImage.ImageOpened += new EventHandler<RoutedEventArgs>(OnDownloadSuccess);
            bitmapImage.ImageFailed += new EventHandler<ExceptionRoutedEventArgs>(OnDownloadFailed);
            bitmapImage.UriSource = a_imageSource;

            _image.Source = bitmapImage;
        }

        /// <summary>
        /// When the download progress changes.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected virtual void OnDownloadProgress(object sender, DownloadProgressEventArgs e)
        {
            _progress.Visibility = Visibility.Visible;
            _progress.Value = e.Progress;
        }

        /// <summary>
        /// When the download succeeds.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected virtual void OnDownloadSuccess(object sender, RoutedEventArgs e)
        {
            _noImage.Visibility = Visibility.Collapsed;
            _progress.Visibility = Visibility.Collapsed;
        }

        /// <summary>
        /// When the download fails.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected virtual void OnDownloadFailed(object sender, ExceptionRoutedEventArgs e)
        {
            _noImage.Visibility = Visibility.Visible;
            _progress.Visibility = Visibility.Collapsed;
        }

        /// <summary>
        /// When SourceProperty dependency property changes.
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="e"></param>
        private static void OnSourcePropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
        {
            DownloadImage downloadImage = obj as DownloadImage;
            if (downloadImage != null)
            {
                if (e.NewValue is Uri)
                    downloadImage.Create(e.NewValue as Uri);
                else if (e.NewValue is BitmapImage)
                    downloadImage.Create(e.NewValue as BitmapImage);
                else
                    return;
            }
        }

    }

And here is the XAML:

<UserControl x:Name="userControl" x:Class="{Intentionally Left Blank}.DownloadImage"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:helpers="clr-namespace:{Intentionally Left Blank}.Helpers"
             xmlns:res="clr-namespace:{Intentionally Left Blank}.Resources"
             xmlns:ee="http://schemas.microsoft.com/expression/2010/effects"
             mc:Ignorable="d"
             d:DesignHeight="100" d:DesignWidth="100" Background="{StaticResource ImageBackground}">
    <Grid x:Name="LayoutRoot" Background="{Binding Background, ElementName=userControl}">
        <Viewbox HorizontalAlignment="Center" VerticalAlignment="Center" Margin="8">
            <TextBlock x:Name="_noImage" TextWrapping="Wrap" FontSize="16"
                res:Strings.Assignment="Text=DownloadImage.NoImage" Height="23" Width="79" Visibility="Collapsed">
                <TextBlock.Foreground>
                    <SolidColorBrush Color="{StaticResource GrayLetters}"/>
                </TextBlock.Foreground>
            </TextBlock>
        </Viewbox>
        <Image x:Name="_image"/>
        <ProgressBar x:Name="_progress" Height="15" VerticalAlignment="Bottom" Margin="1" Visibility="Collapsed"/>
    </Grid>
</UserControl>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T14:35:05+00:00Added an answer on May 22, 2026 at 2:35 pm

    I’m not sure why it worked, but I added the following code to DownloadImage and memory is stable.

        /// <summary>
        /// Default C'tor
        /// </summary>
        public DownloadImage()
        {
            InitializeComponent();
    
            Unloaded += new RoutedEventHandler(OnUnloaded);
        }
    
        /// <summary>
        /// When the control is unloaded.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnUnloaded(object sender, RoutedEventArgs e)
        {
            BitmapImage bitmapImage = _image.Source as BitmapImage;
            if (bitmapImage != null)
            {
                bitmapImage.DownloadProgress -= new EventHandler<DownloadProgressEventArgs>(OnDownloadProgress);
                bitmapImage.ImageOpened -= new EventHandler<RoutedEventArgs>(OnDownloadSuccess);
                bitmapImage.ImageFailed -= new EventHandler<ExceptionRoutedEventArgs>(OnDownloadFailed);
            }
    
            _image.Source = null;
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to write a function that accepts any container holding strings. Something like
So I've been holding off asking this question for a while because I know
i have 4 labels in my view holding scores how can i sort that
Something is wrong with my Rails app because when I run bundle install, I
Something that seems to be absent from the otherwise great new features for Windows
Something that I think is really strange is happening when I use die() .
Something like this: _declspec(align(16)) float dens[4]; //Here the code comes. F32vec4 S_START, Pos, _Vector
I have created a custom comboBox that supports images in front of the items
i`m trying to learn classes, and something is holding em back, i get NameError:
Suppose I have code something like this: #include boost/thread/mutex.hpp using boost::mutex; typedef mutex::scoped_lock lock;

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.