Question about Deletion of objects

So in my Ondraw member of the view class, I create and use two pens aside from the standard black one..

My question.. is it crucial to delete the added pens at the end of the ondraw funtion?

so what i'm doing is,

- I make a blue pen (then select it) and draw with it
- I make a red pen (then select it) and draw with it
-when i'm done i select the old black pen
- then i delete the blue and red pens at the end of the fuction

so does this really do anything?? cause it appears to make no difference whether i delete or not. Is there some kind of memory issue with this?? kind of like when you dynamically allocate memoty.. where you should always delete??

open up task manager and select it to view user objects, gdi objects, and handles. You will probably see those start to climb if you don't delete these gdi objects. It may seem ok at first, but after a while you will notice weird things happen, like windows of other apps failing to create or icons start to turn weird colors on your taskbar and such.

Always call DeleteObject when you are done using the created pen. If you don't delete the pen you may not notice a memory leak at first, but it will become apparent when your application has been running awhile.