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
Solved

freeing objects memory leak and common controls

Posted on 2000-05-17
4
219 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
ID: 2819858
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
ID: 2820803
>> 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
ID: 2823949
how do I do that?
0
 

Author Comment

by:abulka
ID: 2823975
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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…
Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

809 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