Question about Deletion of objects

This is a discussion on Question about Deletion of objects within the Windows Programming forums, part of the Platform Specific Boards category; Hello, So in my Ondraw member of the view class, I create and use two pens aside from the standard ...

  1. #1
    Registered User
    Join Date
    Sep 2003
    Posts
    55

    Question about Deletion of objects

    Hello,

    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??

    Thanks

  2. #2
    Unregistered User
    Join Date
    Sep 2005
    Location
    Antarctica
    Posts
    341
    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.

  3. #3
    Registered User
    Join Date
    Sep 2003
    Posts
    55
    thanks

  4. #4
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,254
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. most efficient way to write filestream objects?
    By darsunt in forum C++ Programming
    Replies: 3
    Last Post: 01-26-2009, 05:17 PM
  2. How to rotate child objects in 3D
    By Arianiv in forum Game Programming
    Replies: 11
    Last Post: 04-03-2008, 06:09 AM
  3. array of objects?
    By *~*~*~* in forum C++ Programming
    Replies: 4
    Last Post: 05-31-2003, 06:57 PM
  4. Very simple question, problem in my Code.
    By Vber in forum C Programming
    Replies: 7
    Last Post: 11-16-2002, 03:57 PM
  5. Objects, or pointers to objects?
    By Unregistered in forum C++ Programming
    Replies: 5
    Last Post: 12-18-2001, 12:57 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21