[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Resource leak

Posted on 2007-03-26
3
Medium Priority
?
389 Views
Last Modified: 2013-11-20
I have some icons that I place in a new CImageList in the OnCreate in CMainFrame.  I the set several set them as icons to several of my buttons.  In the destructor for CMainFrame, I DeleteImageList() and then delete the CImageList.  When I close the program, Boundschecker tell me that I have resource leaks and tells me that I have to delete the icons that I set to the buttons so in OnClose for CMainFrame I tried to delete the icons like this for each button:
      CButton* btn;
      btn = (CButton*)m_wndMyCTRLBar.GetDlgItem( IDC_BUTTON1);
      DestroyIcon(btn->GetIcon());

Boundschecker still says that I have the resource leaks.  Am I suppose to delete them from another event or am I deleting them incorrectly.  Please help end my confusion.
 
0
Comment
Question by:ITSpgrmr
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 86

Assisted Solution

by:jkr
jkr earned 400 total points
ID: 18793780
I'd rather suggest to do that in the destructor of your control bar. Apart from that, what does 'DestroyIcon()' return and what 'GetLastError()' if it returns FALSE?
0
 
LVL 39

Accepted Solution

by:
itsmeandnobodyelse earned 1600 total points
ID: 18793974
How did you get the HICON handles for the bitmaps? Did you get them by a LoadIcon ? If so, Boundschecker may be wrong cause the resource handles came from the already loaded resource file and don't need to be freed. At least there is no FreeIcon function to call. If you load the icons from file the case is different.

Regards, Alex
0
 
LVL 1

Author Comment

by:ITSpgrmr
ID: 18794217
itsmeandnobodyelse:
I did use LoadIcon and I was getting the icons from the resources and not from files.  So I don't have to worry about it since the resources in the resource file get dumped at the end.  That makes since and I like that answer.

jkr:
DestroyIcon() was returning TRUE.

 I agree, taking care of the icons in the destructor of the toolbar is much better.  Sometimes looking back at my code, I wonder what I was thinking.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Suggested Courses

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question