Skip to content

SP4 FormsPlot: Undisposed bitmaps #2902

@mocakturk

Description

@mocakturk

Bug Report

Issue:
After opening/closing hundreds of plots over the time, ArgumentException is thrown from ControlBackEnd.Resize method.

 ---> System.ArgumentException: Parameter is not valid.
   at ScottPlot.Control.ControlBackEnd.Resize(Single width, Single height, Boolean useDelayedRendering)
   at System.Windows.Forms.Control.OnSizeChanged(EventArgs e)

I assume it is from the below line:

Bmp = new System.Drawing.Bitmap((int)width, (int)height);

I have an idea for the root cause:
When the a plot is resizing, new bitmap is created. 3 old bitmaps are kept on a stack. When the plot is closed, the bitmaps are not disposed. If the application opens/closes hundreds of plots over the time, ArgumentException is thrown, because there is no more memory to create bitmap.
Perhaps, making the class disposible, and calling it from deconstructor may fix the issue.

Reproducing:
It is not easy to reproduce the issue. Issue happens on several users who use the app for a long time.
I check the number of GDI Objects from Task Manager, and notice that it is increasing eventhough I close the plots.

System Details

  • ScottPlot Version: 4.1.65
  • Operating System: Windows 10
  • Application Type: WinForms
  • .NET Version: .NET 7.0

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions