VB 2013应用程序内存不足 [英] VB 2013 Application Out of Memory

查看:117
本文介绍了VB 2013应用程序内存不足的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是VB的新手,但是最近创建了我的第一个可运行的应用程序:)无论如何,它只是压缩文件而已.我添加的最新内容是选取框样式的进度条,可以在操作进行时进行动画处理,并在操作结束时停止播放,用户可以进行下一个zip操作.进度条没有更新,因此我使用了背景工来执行实际任务,而单击按钮只是完成动画.从那时起,我就注意到该应用程序中的严重降级.它很难加载.我什至遇到内存不足的错误.不知道后台工作程序是否相关,但是我想提及一下,因为这是最后一次更新.有没有人经历过类似的经历?如果我可以提供具体信息,请询问我!非常感谢.

I'm new to VB but recently created my first working app :) Anyway it just compresses files and little bit more. The latest thing that I added was a marquee style progress bar to animate while the operation was in progress and stop when it ends and the user can do the next zip operation. The progress bar wasn't updating, so I used a background worker to do the actual task while the button click just did the animation. Since then I've notcied serious degredation in the app. It struggles to load. I even got an out of memory error. Not sure if the background worker is related, but I thought I'd mention as it was the last update. Has anyone experienced anything similar? If I can provide and specific info, please ask me for it! Many thanks.

更新:所以我知道我没有正确使用BGWorker.我会改变的.但是我发现即使删除了它,我仍然有问题.因此,我创建了一个新表单,并开始一个接一个地添加我的代码.无论如何,我在表单加载子方面遇到了第一个障碍.所以我慢慢添加了它.我发现,无论何时我有任何语句都可以从该应用加载的持久设置的设置中加载变量.下面是我的代码.谁能看到最新消息吗????

UPDATE: So I understand that I'm not using the BGWorker correctly. I will change that. But I found even with that removed, I still had issues. So I created a new form and started adding in bits of my code one by one. Anyway, I fell at the first hurdle with my form load sub. So I added that in slowly. I found that when ever I have any statements that load a variable from settings for persistent settings that the app falls over. Below is my code. Can anyone see what's up?????

更新:我发现,如果从设置加载,内存使用率会急剧上升.我也尝试过在关闭表单时保存settins的方法.以下是收到的错误.尝试加载设置时,也会发生相同的内存不足.我从未在创建的第一个表格上经历过这种情况.所以也许我错过了第二个设置,因为代码中的实现没有更改.

UPDATE: I've found that if I load from settings the memory useage shoots up. I tried this too with saving settins on form closed. Below is the error received. The same out of memory occurs when trying to load settings too. I never experienced this on the first form I created. So perhaps I have missed some settings on the second, because the implementation in the code hasn't changed.

System.Configuration.ConfigurationErrorsException:无法保存设置:对userSettings/Backup_Tool.My.MySettings执行配置节处理程序时发生错误. ---> System.Configuration.ConfigurationErrorsException:执行userSettings/Backup_Tool.My.MySettings的配置节处理程序时发生错误. ---> System.OutOfMemoryException:引发了类型为'System.OutOfMemoryException'的异常

System.Configuration.ConfigurationErrorsException: Failed to save settings: An error occurred executing the configuration section handler for userSettings/Backup_Tool.My.MySettings. ---> System.Configuration.ConfigurationErrorsException: An error occurred executing the configuration section handler for userSettings/Backup_Tool.My.MySettings. ---> System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown

这是我在下面的代码中添加的内容:

This is when I added in the code below:

Private Sub Form1_Closed(sender As Object, e As EventArgs) Handles MyBase.FormClosed

    ' TAB PAGE 1.

    ' Save controls to settings.

    My.Settings.StartPathTextBox1 = StartPathTextBox1.Text
    My.Settings.ZipPathTextBox1 = ZipPathTextBox1.Text
    My.Settings.CopyPathTextBox1 = CopyPathTextBox1.Text

    My.Settings.ZipSelectCheckBox1 = ZipSelectCheckBox1.Checked
    My.Settings.CopySelectCheckBox1 = CopySelectCheckBox1.Checked

    For Each s As String In StartNameListBox1.Items()
        My.Settings.StartNameListBoxItems1.Add(s)
    Next

    For Each s As String In StartNameListBox1.SelectedItems()
        My.Settings.StartNameListBoxSelectedItems1.Add(s)
    Next

End Sub


Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

    ' FORM 1.

    ' Initialise specialised string collections.

    If My.Settings.StartNameListBoxItems1 Is Nothing Then
        My.Settings.StartNameListBoxItems1 = _
            New System.Collections.Specialized.StringCollection
    End If

    If My.Settings.StartNameListBoxSelectedItems1 Is Nothing Then
        My.Settings.StartNameListBoxSelectedItems1 = _
            New System.Collections.Specialized.StringCollection
    End If

    ' TAB PAGE 1.

    ' Restore controls from saved settings.

    StartPathTextBox1.Text() = My.Settings.StartPathTextBox1
    ZipPathTextBox1.Text() = My.Settings.ZipPathTextBox1
    CopyPathTextBox1.Text() = My.Settings.CopyPathTextBox1

    ZipSelectCheckBox1.Checked = My.Settings.ZipSelectCheckBox1
    CopySelectCheckBox1.Checked = My.Settings.CopySelectCheckBox1

    For Each s As String In My.Settings.StartNameListBoxItems1()
        StartNameListBox1.Items.Add(s)
    Next

    For Each s As String In My.Settings.StartNameListBoxSelectedItems1()
        StartNameListBox1.SelectedItems.Add(s)
    Next

    ' Decide controls initial states.

    If StartNameListBox1.SelectedItems.Count = 0 Then
        ZipSelectCheckBox1.Enabled = False
        RunButton1.Enabled = False
    End If

    If ZipSelectCheckBox1.Checked = False Then
        ZipPathTextBox1.Enabled = False
        ZipBrowseButton1.Enabled = False
    End If

    If ZipPathTextBox1.Text = String.Empty Then
        CopySelectCheckBox1.Enabled = False
    End If

    If CopySelectCheckBox1.Checked = False Then
        CopyPathTextBox1.Enabled = False
        CopyBrowseButton1.Enabled = False
    End If

    End Sub

推荐答案

似乎是因为您只是将当前选择添加到设置"集合中.当他们进行新选择时,您可能会清除ListBox,但是对于诸如My.Settings.StartNameListBoxItems1:

It appears to be that you are only ever adding the current selections to the Settings collections. You might well clear the ListBox when they make new selections, but you do not do the same thing with the Settings Collections like My.Settings.StartNameListBoxItems1:

For Each s As String In StartNameListBox1.Items()
    My.Settings.StartNameListBoxItems1.Add(s)
Next

该集合将在它已经运行过的所有其他时间中包含所有项,现在您将为其添加更多项.最终,您将有很多很多东西.

The collection will have all the items in it from all the other times it has ever run already and you are now going to add more to it. Eventually you will have many, many, many items in it.

My.Settings.StartNameListBoxItems1.Clear   ' REMOVE ALL OLD ITEMS
' Save just the current items to the collection
For Each s As String In StartNameListBox1.Items()
    My.Settings.StartNameListBoxItems1.Add(s)
Next

在两个集合上都使用.Clear

use .Clear on both Collections

这篇关于VB 2013应用程序内存不足的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆