Solved

freeing objects memory leak and common controls

Posted on 2000-05-17
4
213 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
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 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…

920 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

16 Experts available now in Live!

Get 1:1 Help Now