Solved

freeing objects memory leak and common controls

Posted on 2000-05-17
4
210 Views
Last Modified: 2008-10-12
I have an activeX dll with a routine as follows below.

After my app runs for a while, draw glitches start to happen i.e. text that should be drawn by my routine (below) are not drawn.

About this time, the
icons and text in the File/Save dialog box are screwy.  Other apps on the
win98 machine have their file/save dialog boxes screwed too.  We have
installed the latest 50comctl common controls, so they should be ok.

I have NO problems on my own NT development machine, and furthermore,
process viewer & task manager indicate normal memory usage, even when I
stress the app with dozens of nodes.  Its the Win98 Acer laptop machine that has the troubles.

I don't explicitly free stlStrings, logFont, andyFont or res is this a problem?  Other ideas on what might be going on?


#include <list>
#include <string>
#include<vector>

using namespace std;


TSRect CNodeViewReason2::draw3texts(TSEDC & rDC, TSEFontSelector * pFontSelector, string s1,string s2,string s3)
{
    TSRect res;
    vector<string> stlStrings;
    LOGFONT logFont;
      
    TSEFont andyFont(&logFont);
    pFontSelector->select(andyFont);
    font().GetObject(logFont);    // font() returns a TSEFont object

    // looping quite a bit
    stlStrings.push_back(curSent);

    TextOut(....);

   // I don't explicitly free stlStrings, logFont, andyFont or res
   // is this a problem?
}
0
Comment
Question by:abulka
  • 2
4 Comments
 

Accepted Solution

by:
BKnet earned 70 total points
Comment Utility
Hi..
You must delete your font object before quit your function.

Windows has limit handle for font handle, if you run the resoure monitor of windows, you w'll fine how your resoure down !!!.
0
 
LVL 22

Expert Comment

by:nietod
Comment Utility
>> You must delete your font object
>> before quit your function.
The font object was declared local, it should not be deleted.

The TSEFont class seems to be creating a font, does it also delete that font when the class is destroyed?

What does pfontSelector do?

we really can't help much because these classes are all meaningless to us.  You have to provide more details.
0
 

Author Comment

by:abulka
Comment Utility
how do I do that?
0
 

Author Comment

by:abulka
Comment Utility
BKnet is right - it was a font object leak.  thanks.  the solution, as nietod comments, is quite class specific viz:

Replace:
pFontSelector->select(andyFont);
With:
CPen * pOldPen = rDC.SelectObject((CPen *) &andyFont)

and adding
  rDC.SelectObject(pOldPen);

seems to fix the problem.  This solution was recommended to me from another source, and I actually don't understand it.  If someone wants to comment on this, I'd love to know!

0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

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…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
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.

771 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now