如何结束Windows Phone 8中的系统输出内存异常?

时间:2014-05-14 05:37:53

标签: xaml windows-phone-8

我正在开发Windows Phone 8应用程序。

在我的应用程序中,我使用listbox.I绑定列表框值表单Webservice。 Webservice返回json格式数据。

webservice返回40到50条记录。我将所有值绑定到列表框中。

转换工作正常。仅在第一次运行时。

例如: -

我的项目页面结构。

1.welcomepage
2.Menu Page (it contain six buttons. click on any one particular button it's redirect to sub-menupage)
3.Sub-menupage(Six different page present)

在菜单页面中,酒店按钮存在。如果点击酒店按钮,则会导航到酒店页面。

现在我的问题是: -

第一次 - 欢迎页面 - >菜单页面 - > HotelSubmenu [酒店列表在webservice列表框中绑定]               现在,我点击硬件返回按钮,然后点击Menupage。现在它在菜单页面

如果我再次点击相同的酒店按钮

它显示错误

e.ExceptionObject {system.OutofMemoryException:Insufficient memory to continue the execution of the program.
[System.outofmemoryException]
Data        {system.Collections.ListDictionaryInternal}
HelpLink    null
Hresult     -2147024882
Message     "insufficient memory to continue the execution of the program"

我在列表框中绑定值的C#代码

public void commonbind()
    {
        try
        {


            this.loadimg.Visibility = System.Windows.Visibility.Visible;
            loadcheck();

            string common_url = "http://xxxxxx.com/Service/bussinesscitynamesub.php?bcatid=" + businessid + "&cityname=" + cityname + "&bsubid=" + filterid;
            WebClient common_wc = new WebClient();

            common_wc.DownloadStringAsync(new Uri(common_url), UriKind.Relative);
            common_wc.DownloadStringCompleted += common_wc_DownloadStringCompleted;

        }
        catch (Exception ex)
        {

        }
    }


 void common_wc_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
    {
        try
        {

            lbbusiness.Items.Clear();
            var common_val = e.Result;
            if (common_val != "null\n\n\n\n")
            {
                lbopen = 2;
                var jsonconvertvalue = JsonConvert.DeserializeObject<List<common_bindclass>>(common_val);

                List<common_bindclass> ls = new List<common_bindclass>();
                ls = jsonconvertvalue;


                for (int i = 0; i < ls.Count; i++)
                {
                    lbbusiness.Items.Add(ls[i]);
                }


                this.loadimg.Visibility = System.Windows.Visibility.Collapsed;
                loadcheck();
            }
            else
            {

                if (lbopen == 0)
                {

                    MessageBoxResult resultmsg = MessageBox.Show("No Result present based on your current Location! " + System.Environment.NewLine + "Now showing result without Location based", "Sorry!", MessageBoxButton.OK);

                    if (resultmsg == MessageBoxResult.OK)
                    {
                        lbbusiness.Items.Clear();
                        cityname = "";
                        **commonbind();**
                    }
                    else
                    {
                        NavigationService.GoBack();
                    }

                }

                else if (lbopen == 1)
                {

                    MessageBox.Show("No Result Present In this Categories");
                    LPfilter.Open();
                }

                else if (lbopen == 2)
                {

                    MessageBox.Show("No Result Present In this City");
                    Lpcity.Open();
                }
            }
        }
        catch (Exception ex)
        {

        }
    }

我尝试使用以下方法来解决内存异常

Try1: -     每次绑定前清除列表框值。

Try2: -

每次创建新列表

 common_bindclass bind = new common_bindclass();

 foreach (common_bindclass bind in jsonconvertvalue)
                {
                   lbbusiness.Items.Add(bind);
                }

我将上面的代码更改为

 List<common_bindclass> ls = new List<common_bindclass>();
                ls = jsonconvertvalue;

 for (int i = 0; i < ls.Count; i++)
                {
                    lbbusiness.Items.Add(ls[i]);
                }

单个列表的MY输出

enter image description here

但我的尝试对我没有帮助。

任何人都告诉我如何解决它。或替代方式。

如何查找错误发生在哪一行。[我尝试使用断点,但它没有帮助我]

0 个答案:

没有答案