Is it important to dispose SolidBrush and Pen?

后端 未结 6 883
别跟我提以往
别跟我提以往 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:25

    It's just leaking un-managed resources (the pen/brush) until the corresponding managed object is reclaimed by the garbage collector. So you're wasting a few handles that aren't used afterwards anymore.

    It's not too big a deal because Finalize() will call Dispose() but releasing unmanaged resources should usually be done rather sooner than later.

提交回复
热议问题