 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Ian Hodgson Guest
|
Posted: Thu Sep 09, 2004 12:31 pm Post subject: TImage & Memory problem |
|
|
Hello,
I have an application that displays photographs in a folder stored as .jpg.
I use a TImage on a form, and everytime the user presses a cursor key, a new
image is loaded and displayed in the TImage. The problem is that everytime
the user selects a new image, the memory usage goes up. Eventually windows
(2000) reports that virtual memory is running low and it resizes it. I have
found (from a previous post)that I can prevent this if I minimize the
application, load the new image and then restore the application which isn't
really acceptable. Is there something I can do to force whatever is
happening during the minimize / restore without actually having to minimize?
Ian
|
|
| Back to top |
|
 |
Nils Haeck Guest
|
Posted: Thu Sep 09, 2004 2:43 pm Post subject: Re: TImage & Memory problem |
|
|
It sounds like you forget to free a resource. This could either be the
bitmap, the jpeg, or some other kind of stream.
Always make sure that whenever you create an object, you also free it. Make
sure to wrap in try..finally blocks to ensure that the destructor is called.
Here's an example:
uses
Jpeg, Graphics;
procedure MyForm.ReadNextImage(Filename: string);
var
AJpg: TJpegImage;
ABmp: TBitmap;
begin
AJpg := TJpegImage.Create;
ABmp := TBitmap.Create;
try
AJpg.LoadFromFile(Filename);
ABmp.Assign(AJpg);
//.. do whatever preprocessing is neccesary to the bitmap here.
// Assign it to the image on your form
Image1.Picture.Bitmap.Assign(ABmp);
finally
// Here we free the objects that we created again
ABmp.Free;
AJpg.Free;
end;
end;
Kind regards,
Nils
www.simdesign.nl
"Ian Hodgson" <hodgsoni (AT) hotmail (DOT) com> wrote
| Quote: | Hello,
I have an application that displays photographs in a folder stored as
..jpg.
I use a TImage on a form, and everytime the user presses a cursor key, a
new
image is loaded and displayed in the TImage. The problem is that everytime
the user selects a new image, the memory usage goes up. Eventually windows
(2000) reports that virtual memory is running low and it resizes it. I
have
found (from a previous post)that I can prevent this if I minimize the
application, load the new image and then restore the application which
isn't
really acceptable. Is there something I can do to force whatever is
happening during the minimize / restore without actually having to
minimize?
Ian
|
|
|
| Back to top |
|
 |
Ian Hodgson Guest
|
Posted: Fri Sep 10, 2004 8:13 am Post subject: Re: TImage & Memory problem |
|
|
Thanks Nils,
I was using the GraphicsConversionsLibrary to load the image, but loading it
directly into a TImage, each successive load must have been leaving the
previous one in memory. I have changed it to dynamically create a bitmap,
load the image into the bitmap, assign the bitmap to the image and then free
the bitmap. Seems to do the trick.
Ian
"Nils Haeck" <n.haeckno (AT) spamchello (DOT) nl> wrote
| Quote: | It sounds like you forget to free a resource. This could either be the
bitmap, the jpeg, or some other kind of stream.
Always make sure that whenever you create an object, you also free it.
Make
sure to wrap in try..finally blocks to ensure that the destructor is
called.
Here's an example:
uses
Jpeg, Graphics;
procedure MyForm.ReadNextImage(Filename: string);
var
AJpg: TJpegImage;
ABmp: TBitmap;
begin
AJpg := TJpegImage.Create;
ABmp := TBitmap.Create;
try
AJpg.LoadFromFile(Filename);
ABmp.Assign(AJpg);
//.. do whatever preprocessing is neccesary to the bitmap here.
// Assign it to the image on your form
Image1.Picture.Bitmap.Assign(ABmp);
finally
// Here we free the objects that we created again
ABmp.Free;
AJpg.Free;
end;
end;
Kind regards,
Nils
www.simdesign.nl
"Ian Hodgson" <hodgsoni (AT) hotmail (DOT) com> wrote in message
news:41404d0a$1 (AT) newsgroups (DOT) borland.com...
Hello,
I have an application that displays photographs in a folder stored as
.jpg.
I use a TImage on a form, and everytime the user presses a cursor key, a
new
image is loaded and displayed in the TImage. The problem is that
everytime
the user selects a new image, the memory usage goes up. Eventually
windows
(2000) reports that virtual memory is running low and it resizes it. I
have
found (from a previous post)that I can prevent this if I minimize the
application, load the new image and then restore the application which
isn't
really acceptable. Is there something I can do to force whatever is
happening during the minimize / restore without actually having to
minimize?
Ian
|
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|