[ Show ]
Support VoyForums
[ Shrink ]
VoyForums Announcement: Programming and providing support for this service has been a labor of love since 1997. We are one of the few services online who values our users' privacy, and have never sold your information. We have even fought hard to defend your privacy in legal cases; however, we've done it with almost no financial support -- paying out of pocket to continue providing the service. Due to the issues imposed on us by advertisers, we also stopped hosting most ads on the forums many years ago. We hope you appreciate our efforts.

Show your support by donating any amount. (Note: We are still technically a for-profit company, so your contribution is not tax-deductible.) PayPal Acct: Feedback:

Donate to VoyForums (PayPal):

Login ] [ Contact Forum Admin ] [ Main index ] [ Post a new message ] [ Search | Check update time | Archives: 12345[6]78910 ]

[ Next Thread | Previous Thread | Next Message | Previous Message ]

Date Posted: 11:07:10 03/17/02 Sun
Author: Mark Chambers
Subject: memory leak in TRubberBandMouseHandler

Hi - the method TRubberBandMouseHandler.MouseUp allocates a DibGraphic object in order to pass it to the callback method. It is then up to the callback method to delete it. (This isn't generally a good idea - responsibilty for destruction should rest with the creator) Unfortunately, MouseUp creates the DibGraphic regardless of whether or not there is a callback method - and if there isn't, then it never gets cleanedup. My suggested fix follows.

Mark Chambers

procedure TRubberBandMouseHandler.MouseUp(const Button: TMouseButton;
const Shift: TShiftState; const X, Y: Integer);
DibGraphic: TDibGraphic;
Temp: integer;

FBottom:= Y;
FRight:= X;

if (FTop <> FBottom) and (FLeft <> FRight) then begin

if FTop > FBottom then begin
Temp:= FTop;
FTop:= FBottom;
FBottom:= Temp;

if FLeft > FRight then begin
Temp:= FLeft;
FLeft:= FRight;
FRight:= Temp;

if Assigned(FCallback) then begin
DibGraphic:= TDibGraphic.Create;
FRight - FLeft, FBottom - FTop,
(FImageScrollBox.FImage.Picture.Graphic as TDibGraphic).ImageFormat,
@(FImageScrollBox.FImage.Picture.Graphic as TDibGraphic).Palette,
(FImageScrollBox.FImage.Picture.Graphic as TDibGraphic).XDotsPerInch,
(FImageScrollBox.FImage.Picture.Graphic as TDibGraphic).YDotsPerInch

Rect(0, 0, FRight - FLeft - 1, FBottom - FTop - 1),
(FImageScrollBox.FImage.Picture.Graphic as TDibGraphic).Canvas,
Rect(FLeft, FTop, FRight, FBottom)

FCallback(FTop, FLeft, FBottom, FRight, DibGraphic);
// DibGraphic.Free;
// not freed as it might be kept by the callback routine.
// this is not a good practice! We should free it ourselves (and
// expect the CallBack method to copy it, or just pass the
// FImageScrollBox.FImage.Picture.Graphic (or just FImageScrollBox)
// and let the callback do what it wants.
// I think this should be changed to at least free the
// DibGraphic, but the I don't have to manage all
// the complaints that will ensue!

Screen.Cursor:= FScreenCursor;

[ Next Thread | Previous Thread | Next Message | Previous Message ]


[ Contact Forum Admin ]

Forum timezone: GMT-5
VF Version: 3.00b, ConfDB:
Before posting please read our privacy policy.
VoyForums(tm) is a Free Service from Voyager Info-Systems.
Copyright © 1998-2019 Voyager Info-Systems. All Rights Reserved.