The function CreateSolidBrush
cannot know how you are using it. It can't know that you aren't storing the handle and therefore perform some automatic clean up. Since the documentation of CreateSolidBrush
specifies that you should call DeleteObject
with the returned handle, you should make sure you abide by those requirements.
If you don't store the handle, then you lose access to it and can't ensure that the object is destroyed.