Freeing memory taken up by SetItemData()

This is a discussion on Freeing memory taken up by SetItemData() within the Windows Programming forums, part of the Platform Specific Boards category; I'm using a CTreeCtrl and SetItemData to set the node data. It would make sense that the Win32 API would ...

  1. #1
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,597

    Freeing memory taken up by SetItemData()

    I'm using a CTreeCtrl and SetItemData to set the node data. It would make sense that the Win32 API would handle freeing this data, but it does not. Every time I create a layer in my editor, I leak 8 bytes per layer when closing the program.

    How do I free this data? CTreeCtrl::DeleteAllItems() does not work.

  2. #2
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    The treeview control is only responsible for itself, not any data you assign.

    Handle the control's TVN_DELETEITEM notification which will be issued as each item is deleted from the tree, thereby giving you a convenient opportunity to free up any memory you have assigned to the control.

    Alternatively, if your data pointers have suitable scope, then you can clean up when the application quits (WM_CLOSE, WM_DESTROY).

    If it's not actually your data that's the issue, then it may be a problem with mfc's implementation of the underlying winapi treeview control, in which case you may have to use the corresponding winapi macros/functions/messages directly to bypass the problem.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  3. #3
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,597
    Thanks, I'll give it a go and see what happens.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. memory freeing function
    By johndoe in forum C Programming
    Replies: 4
    Last Post: 02-17-2006, 02:08 AM
  2. Freeing memory for non-pointer variables
    By SuperGodAntMan in forum C++ Programming
    Replies: 7
    Last Post: 02-11-2006, 01:30 AM
  3. pointers
    By InvariantLoop in forum C Programming
    Replies: 13
    Last Post: 02-04-2005, 09:32 AM
  4. memory allocation and freeing
    By Jase in forum Linux Programming
    Replies: 1
    Last Post: 05-25-2003, 07:26 AM
  5. freeing memory
    By mart_man00 in forum C Programming
    Replies: 1
    Last Post: 04-27-2003, 09:51 PM

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