我正在开发条形码扫描仪。 我的应用程序扫描条形码,而不是导航到第二页(上面有条形码文本),还有一个按钮,我可以在单击时扫描新的条形码。所以现在我的问题是,每次扫描条形码时,取景器都会填充Windows手机的Ram。如果我扫描100个条形码,我的应用程序因内存不足而崩溃。我该怎么办才能释放记忆?
在zxing演示中同样的问题,当我打开扫描仪并使用后退键并再次打开扫描仪时,撞锤越来越高。
获取ram的代码:
string storage1 = (DeviceStatus.ApplicationCurrentMemoryUsage / 1000000).ToString() + "MB";
lblram.Text = storage1 ;
我尝试了一切: 1. Navigationservice.removebackstack 2. Gc.collect(Garbagecollector) 3.丢弃相机 4.使用navigationservice.goback()
没有任何帮助
我发现问题是取景器,但我每次都要对它进行初始化,这就是问题。
代码:
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
string bla1 = (DeviceStatus.ApplicationCurrentMemoryUsage / 1000000).ToString() + "MB";
lblram.Text = bla1;//("Ram: " + Math.Round(((bla1 / 1024)/ 1024), 2));
_matches = new ObservableCollection<string>();
matchesList.ItemsSource = _matches;
// Check to see if the camera is available on the phone.
if (PhotoCamera.IsCameraTypeSupported(CameraType.Primary) == true)
{
_photoCamera = new PhotoCamera(CameraType.Primary);
// Event is fired when the PhotoCamera object has been initialized.
_photoCamera.Initialized += PhotoCameraOnInitialized;
_photoCamera.AutoFocusCompleted += PhotoCameraOnAutoFocusCompleted;
NavigationService.RemoveBackEntry();
viewfinderBrush.SetSource(_photoCamera);
}
else
{
// The camera is not supported on the phone.
MessageBox.Show("A Camera is not available on this phone.");
}
}
我该怎么做才能解决这个问题?