简体   繁体   中英

Out of memory exception while loading images from isolated storage

I am getting OutofMemoryException in this particular code.

public BitmapImage GetImage(int pageNo)
        {
            if (!this._isLoaded)
            {
                this.Load();
            }
            using (IsolatedStorageFileStream stream = IsolatedStorageFile.GetUserStoreForApplication().OpenFile(this.FileNames[pageNo], FileMode.Open, FileAccess.Read))
            {
                BitmapImage image = new BitmapImage();
                image.SetSource(stream);            

                return image;

            }
        }

The out of memory exception is occuring at image.SetSource(stream) . I cant set the uri to null because I have to return the image.

What is the workaround for this? Help me here.

I had this list of bitmap images.

 private List<BitmapImage> _images = new List<BitmapImage>();

I cleared the uri while leaving the page.

 protected override void OnNavigatedFrom(NavigationEventArgs e)
        {
            base.OnNavigatedFrom(e);
            this.DataContext = null;
            foreach (var obj in this._images)
            {
                if (obj != null)
                {
                    obj.ClearValue(BitmapImage.UriSourceProperty);
                }

            }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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