Feature evaluation was disabled due to a memory exception

I am getting this "Function evaluation was disabled due to an out of memory exception" exception from this line of code.

this.pbErrorSign.BackgroundImageLayout =   System.Windows.Forms.ImageLayout.Stretch;

      

In fact, I've added a background image and many other images like warning images and picture frames instead of buttons to create an attractive GUI. The program was fine a while ago and now it gave me this .... help plz

the following code is from the designer.

 this.pbErrorSign.BackColor = System.Drawing.Color.Transparent;
        this.pbErrorSign.BackgroundImage = global::SAMS.Properties.Resources.ErrorSign3;
        this.pbErrorSign.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
        this.pbErrorSign.Location = new System.Drawing.Point(69, 121);
        this.pbErrorSign.Name = "pbErrorSign";
        this.pbErrorSign.Size = new System.Drawing.Size(30, 30);
        this.pbErrorSign.TabIndex = 1;
        this.pbErrorSign.TabStop = false;

      

Below is the code of a form named errorDialogForm

public partial class ErrorDialogForm : Form
{
    protected override void OnShown(EventArgs e)
    {
        base.OnShown(e);
        this.Capture = true;
    }



    public ErrorDialogForm()
    {
        InitializeComponent();
    }

    public string LabelText
    {
        get
        {
            return this.lblError.Text;
        }
        set
        {
            this.lblError.Text = value;
        }
    }



    private void pbOkButton_Click(object sender, EventArgs e)
    {
        this.Close();
    }

    private void pbOkButton_MouseEnter(object sender, EventArgs e)
    {
        this.pbOkButton.BackgroundImage = ((System.Drawing.Image)(Properties.Resources.purpleOkButton));
    }

    private void pbOkButton_MouseLeave(object sender, EventArgs e)
    {
        this.pbOkButton.BackgroundImage = ((System.Drawing.Image)(Properties.Resources.blueOkButton));
    }



    private void ErrorDialogForm_Enter(object sender, EventArgs e)
    {
        this.Close();
    }

    private void ErrorDialogForm_Deactivate(object sender, EventArgs e)
    {
        this.Close();
    }

    private void ErrorDialogForm_FormClosing(object sender, FormClosingEventArgs e)
    {
        this.Hide();
        this.Parent = null;
        e.Cancel = true;
    }


}

      

+3


source to share


1 answer


Feature evaluation was disabled due to a memory exception

This is a notification about the debugger, it just tells you that it is not going to show you anything because the program crashed with OOM. Chances are very high that the debugger will also crash when this happens. The real problem is the OOM exception you got that caused the debugger to stop the program.

this.pbOkButton.BackgroundImage = Properties.Resources.purpleOkButton;



This is the expression that caused the crash. You do this in events that fire very often when you move the mouse. What's not so obvious is that this statement creates a new Bitmap object. The old ones don't give orders. This allows you to quickly use up your program's memory with little chances that the garbage collector might do something because you are not allocating any other objects. The OOM kaboma is pretty inevitable.

The correct fix is ​​to create these bitmaps only once:

private Image purpleOk;
private Image blueOk;

public ErrorDialogForm()
{
    InitializeComponent();
    purpleOk = Properties.Resources.purpleOkButton;
    blueOk = Properties.Resources.blueOkButton;
    pbOkButton.BackgroundImage = blueOk;
}

private void pbOkButton_MouseEnter(object sender, EventArgs e)
{
    this.pbOkButton.BackgroundImage = purpleOk;
}

private void pbOkButton_MouseLeave(object sender, EventArgs e)
{
    this.pbOkButton.BackgroundImage = blueOk;
}

protected override void OnFormClosed(FormClosedEventArgs e) 
{
    purpleOk.Dispose();
    blueOk.Dispose();
    base.OnFormClosed(e);
}

      

+1


source







All Articles