Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

freeing objects memory leak and common controls

Posted on 2000-05-17
4
Medium Priority
?
231 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
[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
  • 2
4 Comments
 

Accepted Solution

by:
BKnet earned 140 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

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…
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
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…

721 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