Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4062060
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T15:33:03+00:00 2026-05-20T15:33:03+00:00

I am running an application developed with RAD Studio XE or Delphi XE under

  • 0

I am running an application developed with RAD Studio XE or Delphi XE under Windows 7. After rebuilding my application from previous project files, I have been testing its functionality, but the application would only run for about a month or so and starts to fail slowly. This application is supposed to run 24/7 for all time, unless Windows OS fails. So, I ran AQTime on the application for few hours and closely watched the results as the program was running. What I noticed was this. With everything else being constant and still in numbers, under resource profiling Brush, Handle, Pen and another Pen are slowly increasing in numbers especially the second pen and Brush resources. Pen seems to be increasing in numbers by about 522 every second. Also, number of handle is going up but very slowly – maybe every 15 minutes. On a side note: some of our users have had a total
catastrophic failure, where Windows OS will die completely to a point that you have to reinstall Windows again and everything else.

AQTime result:
Class_Name     Object_Name
Brush          Brush:54,947
Handle         Handle:44,559  --Handle is increasing slowly
Pen            Pen:53,378   
Pen            Pen:54,915     --Pen is increasing every second by 522. 

The application’s main window is always going to be displayed on the screen.

UPDATE2:

pen, oldPen Bursh and oldBursh are declared within a base class. They are assigned everytime within the following procedure and the procedure is used throughout the program for drawing elements right on the TForm like circle, polygon, square, line, etc.

procedure TMakerGraphic.SaveCanvas;
begin
  oldPen.Assign(myForm.Canvas.Pen);
  oldBrush.Assign(myForm.Canvas.Brush);
  myForm.Canvas.Pen.Assign(Pen);
  myForm.Canvas.Brush.Assign(Brush);
end;

procedure TMakerGraphic.RestoreCanvas;
begin
  myForm.Canvas.Pen.Assign(oldPen);
  myForm.Canvas.Brush.Assign(oldBrush);
end;

The Only time these variables are released is when the elements on the TForm is deleted as shown by the following Free procedure.

destructor TMakerGraphic.Free;
begin
  Pen.Free;
  Brush.Free;
  oldPen.Free;
  oldBrush.Free;
  inherited Free;
end;

So, is that mean my application is leaking memory?

Any input will be greatly appreciated. Thank you.

  • 1 1 Answer
  • 3 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T15:33:04+00:00Added an answer on May 20, 2026 at 3:33 pm

    It seems that instances of Pen and Brush are not freed properly.

    If you are using the built-in drawing procedures of TCanvas, use

    Canvas.Pen.Assign(anotherPen)
    

    to fill in a new pen.

    If you are using gdiplus.dll via IGDIPlus, each drawing procedure will take a argument of IGPPen or IGPBrush. Thus, either declaring the variables to pass through as IGPPen/IGPBrush; or declaring them as TGPPen/TGPBrush, and free them afterwards.

    ================= temporary space for sample source code ==========

    I would think the following code, as OP gives, does not incur memory/resource leak.

        unit Unit1;
    
        interface
    
        uses
          Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
          Dialogs;
    
        type
          TForm1 = class(TForm)
            procedure FormCreate(Sender: TObject);
          private
            { Private declarations }
            currPen, prevPen: TPen;
            currBrush, prevBrush: TBrush;
    
            procedure FormPaint(Sender: TObject);
            procedure FormDestroy(Sender: TObject);
    
            procedure SaveCanvas;
            procedure RestoreCanvas;
    
          public
            { Public declarations }
          end;
    
        var
          Form1: TForm1;
    
        implementation
    
        {$R *.dfm}
    
        procedure TForm1.FormCreate(Sender: TObject);
        begin
          currPen := TPen.Create;
          prevPen := TPen.Create;
    
          currBrush := TBrush.Create;
          prevBrush := TBrush.Create;
    
          Self.OnPaint := Self.FormPaint;
          Self.OnDestroy := Self.FormDestroy;
        end;
    
        procedure TForm1.FormPaint(Sender: TObject);
        begin
          SaveCanvas;
          RestoreCanvas;
        end;
    
        procedure TForm1.FormDestroy(Sender: TObject);
        begin
          prevPen.Free;
          prevBrush.Free;
          currPen.Free;
          currBrush.free;
        end;
    
        procedure TForm1.SaveCanvas;
        begin
          prevPen.Assign(Self.Canvas.Pen);
          prevBrush.Assign(Self.Canvas.Brush);
          Self.Canvas.Pen.Assign(currPen);
          Self.Canvas.Brush.Assign(currBrush);
        end;
    
        procedure TForm1.RestoreCanvas;
        begin
          Self.Canvas.Pen.Assign(prevPen);
          Self.Canvas.Brush.Assign(prevBrush);
        end;
    
        end.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been running an application developed under Windows 7 in Delphi XE on
I have a Windows Service application (developed in C++) running under Local System account.
We have developed a JEE5 web application (WAR) and running it in production under
I have an application developed to run on a particular cellphone running windows mobile.
I have developed a Phone Gap application using this link . Application is running
I have an application developed in C++ running on Linux. This application opens certain
I have got an application developed with Monotouch 4.0.7. This app is running on
i have developed application while running my application another application ContactManager is also get
We have an running application that is developed in struts-2.0.14 . In this we
Scenario : I have an ASP.NET MVC application developed in Visual Studio 2008. There

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.