none
Memory leak in UWP image access RRS feed

  • Question

  • I created a blank app (VS 2017) with a single button.  The click event code looks like what follows.  This leaks memory like crazy and dies after 2000+ iterations.  Does anyone understand what is wrong here?


            private async void button_Click(object sender, RoutedEventArgs e)
            {
                for (int i = 0; i < 10000; ++i)
                {
                    await LoadMetadata();
                }
            }


            private async Task LoadMetadata()
            {
                string sFile = "Test.jpg";

                StorageFile f = await KnownFolders.PicturesLibrary.GetFileAsync(sFile);

                using (IRandomAccessStreamWithContentType strm = await f.OpenReadAsync())
                {
                    BitmapDecoder decoder = await BitmapDecoder.CreateAsync(strm);
                    BitmapFrame frm = await decoder.GetFrameAsync(0);

                    uint nWidth = decoder.OrientedPixelWidth;
                    uint nHeight = decoder.OrientedPixelHeight;

                    string[] propNames = new string[]
                    {
                        "System.Photo.CameraManufacturer",
                        "System.Photo.CameraModel",
                        "System.Photo.CameraSerialNumber"
                    };

                    BitmapPropertySet props = await frm.BitmapProperties.GetPropertiesAsync(propNames);

                    props.Clear();
                }
            }

    Saturday, March 11, 2017 7:51 PM

All replies