Solved

freeing objects memory leak and common controls

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

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…
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 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 user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

821 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