Is it important to dispose SolidBrush and Pen?

后端 未结 6 876
别跟我提以往
别跟我提以往 2021-01-04 00:55

I recently came across this VerticalLabel control on CodeProject.

I notice that the OnPaint method creates but doesn\'t dispose Pen and SolidBrush objects.

D

6条回答
  •  [愿得一人]
    2021-01-04 01:09

    The objects should be disposed of by the garbage collection after they've fallen out of scope as long as they're not referenced by anything else.

    The simplest way to demonstrate whether this is happening or not (without making any code changes) is to use a large number of these controls on a form and see if the memory used by the application keeps growing or remains stable.

提交回复
热议问题