Board index » cppbuilder » 'nother mem leak q

'nother mem leak q

This section of code seems to be letting memory get away somewhere.... Do I
need to delete more than what I have done? Is there something obvious here I
am missing? I'm kind of hoping there is, otherwise I have a problem
somewhere else.

LOGFONT vFont;
HFONT RFont, PFont;
PassedCanvas->Font->Name = "Times New Roman";
PassedCanvas->Font->Size = TBPAr[Position]->TextSize;
int Mag= PassedCanvas->TextHeight(TBPAr[Position]->PlacedText1);
GetObject(PassedCanvas->Font->Handle, sizeof(vFont), &vFont);
vFont.lfEscapement = 10 * TBPAr[Position]->Angle;
vFont.lfOrientation = TBPAr[Position]->Angle * 10; //this does the rotation
RFont = CreateFontIndirect(&vFont);
PFont = SelectObject(PassedCanvas->Handle, RFont);
...
//a few text outs...
...
PFont = SelectObject(PassedCanvas->Handle, RFont);
RFont = SelectObject(PassedCanvas->Handle, PFont);
DeleteObject(RFont);
DeleteObject(PFont);

Anyway, if someone knows what I am doing wrong (if there is somethign
wrong...) I would looove to know =).

Thanks
Vesty.

 

Re:'nother mem leak q


Hi Vesty .

Quote
Vesty wrote:
> This section of code seems to be letting memory get away somewhere.... Do I
> need to delete more than what I have done? Is there something obvious here I
> am missing? I'm kind of hoping there is, otherwise I have a problem
> somewhere else.

> LOGFONT vFont;
> HFONT RFont, PFont;
> PassedCanvas->Font->Name = "Times New Roman";
> PassedCanvas->Font->Size = TBPAr[Position]->TextSize;
> int Mag= PassedCanvas->TextHeight(TBPAr[Position]->PlacedText1);
> GetObject(PassedCanvas->Font->Handle, sizeof(vFont), &vFont);
> vFont.lfEscapement = 10 * TBPAr[Position]->Angle;
> vFont.lfOrientation = TBPAr[Position]->Angle * 10; //this does the rotation
> RFont = CreateFontIndirect(&vFont);
> PFont = SelectObject(PassedCanvas->Handle, RFont);
> ...
> //a few text outs...
> ...

instead of the next four lines do this :
RFont = SelectObject (PassedCanvas->Handle , PFont ) ;
DeleteObject ( RFont ) ;

Quote
> PFont = SelectObject(PassedCanvas->Handle, RFont);
> RFont = SelectObject(PassedCanvas->Handle, PFont);
> DeleteObject(RFont);
> DeleteObject(PFont);

> Anyway, if someone knows what I am doing wrong (if there is somethign
> wrong...) I would looove to know =).

also check if you need to release the memory you allocated in the call to
GetObject()
I don't remember if you need to do that , so check it .

Quote

> Thanks
> Vesty.

--
          \\\\\////
           / ^ ^ \
         ( (0) (0) )
 *=======oOOO=(_)==OOOo========*
 | Have a nice day...          |
 | Moti Gayer                  |
 | Visit: www.ptc.com          |
 | Email: mga...@ptc.com       |
 *==============Oooo.==========*
       .oooO   (     )
      (     )   )   /
       \   (   (__ /
        \__ )

Other Threads