2014-02-28 5 views
1

내 Windows Phone 8 응용 프로그램에는 LongListSelector이있는 페이지가 있으며 이미지의 경우 base64string 속성을 가진 1000 개의 개체 목록에 바인딩되어 있습니다. 이제 이미지를 표시하기 위해이 변환기를 작성하여 bas64stringstream으로 변환했습니다. 메모리에서Windows Phone 8에서 이미지 캐시/메모리를 확보하는 방법은 무엇입니까?

 
    Memory: 92549120 bytes 
    Memory: 92946432 bytes 
    Memory: 92946432 bytes 
    Memory: 92946432 bytes 
    Memory: 92946432 bytes 
    Memory: 93192192 bytes 
    Memory: 93192192 bytes 
    Memory: 96079872 bytes 
    Memory: 100700160 bytes 
    Memory: 100700160 bytes 
    Memory: 109568000 bytes 
    Memory: 111734784 bytes 
    Memory: 142852096 bytes 
    Memory: 143056896 bytes 
    Memory: 143056896 bytes 
    Memory: 143261696 bytes 
    Memory: 140791808 bytes 
    Memory: 141103104 bytes 
    Memory: 141529088 bytes 
    Memory: 142151680 bytes 
    Memory: 146784256 bytes 
    Memory: 146784256 bytes 
    Memory: 155066368 bytes 
    Memory: 156368896 bytes 

가 같거나 EngineExecutionException이 156,368,896 바이트보다 더 큰 어쩌면 일부 바이트, 응용 프로그램이 충돌 :

public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) 
{ 
    if (!value.ToString().Contains("http://")) 
    { 
     string str = value.ToString(); 
     byte[] bytes = Converter.FromBase64String(str); 

     using (MemoryStream stream = new MemoryStream(bytes)) 
     { 
      stream.Seek(0, SeekOrigin.Begin); 

      BitmapImage image = new BitmapImage(); 
      image.SetSource(stream); 
      bytes = null; 
      var memoryusage = string.Format("Memory: {0} bytes", 
      DeviceExtendedProperties.GetValue("ApplicationCurrentMemoryUsage")); 
      Debug.WriteLine(memoryusage); 
      return image; 
     } 
    } 
    else 
    { 
     return null; 
    } 
} 

는 그리고 이것은 MemoryUsage의입니다. 나는 이것에 대한 "에서 OutOfMemoryException을 가지고 일단 :

image.SetSource(stream); 

는 분명히 이것은 메모리 문제입니다 나는이 대답 https://stackoverflow.com/a/12267163/1949475의 링크를 참조 이미지 캐시 메모리하지만 어떻게 삭제해야합니다,하지만 난 그것을 사용할 수 없습니다입니다.?.

참고 :. 모든 이미지가 동시에 표시, 나는 다시 LongListSelector에 표시되는 데이터를 변경 돌아가서 페이지로 돌아 온 후 응용 프로그램이 많은 메모리를 소요되어 있지

+0

* Convert에서 반환 된 이미지를 어딘가에서 삭제 하시겠습니까? –

+0

아니요 .... 이미지가 xaml의 이미지 요소로 반환됩니다. –

답변

4

그것은이다 변환기 클래스에서 설정하는 것이 중요합니다.

BitmapImage image = new BitmapImage(); 
image.DecodePixelType = DecodePixelType.Logical; 
image.CreateOptions = BitmapCreateOptions.BackgroundCreation; 
image.CreateOptions = BitmapCreateOptions.DelayCreation; 
image.DecodePixelWidth = 56; 
image.DecodePixelHeight = 100; 
+0

여기서 도와주세요. http://stackoverflow.com/questions/24157246/wp8-out-of-memory-error-while-loading-images – Goofy

+0

Isn 임시 해결책이 아닌가? 비트 맵 이미지에 의해 소비되는 메모리를 줄이려고하지만 매우 많은 수의 이미지를로드하면이 문제가 발생하지 않을 것입니다. – Raj123

관련 문제