Board index » delphi » Bitmap.Assign causes memory leak ??

Bitmap.Assign causes memory leak ??

I've encountered the following error and wonder if there may be a way
around this

lets say i have the following code

Image1 : TImage; //which is displayed on screen

Bitmap1 : TBitmap;

while True do begin
  Bitmap1:=TBitmap.Create;
  Bitmap1.LoadFromFile('somebitmap.bmp');
  Image1.Picture.Bitmap.Assign(Bitmap1);
  Bitmap1.Free;
end;

should (will)  the above cause any memory leaks, if so why and how can i
correct it.
What happens to the memory allocated to the bitmap of the previous
image1.picture.bitmap when it is re-assigned top another bitmap.

i'm doing frame grabbing and to display the image i need to display 4
images a second to an image using something like the above

Thanks

Conrad Smith

Please email answer to me as well

 

Re:Bitmap.Assign causes memory leak ??


Quote
> should (will)  the above cause any memory leaks, if so why and how can i
> correct it.
> What happens to the memory allocated to the bitmap of the previous
> image1.picture.bitmap when it is re-assigned top another bitmap.

Have you checked if this gives a memory leak cause I have a hard time
believing it will.  The only thing is that your Bitmap1 is still in memory.
The free procedure is not ment to be used simply like that, at least not
that I have seen it used like that.  If you check the value of Bitmap1 in
the your watches I believe you'll still see a memory segment assigned to it,
you need to add a Bitmap1 := nil to make sure it's released.

For the second part, I would pretty much bet that when you assign an image
to a previously assigned image it simply replaces them, I.E. the pointer now
points to a different sector on the HD.  I might be wrong but I don't think
your code will cause a leak, test it on several images and check to see if
their is a leak.

--
Lior Amar
Computer Consultant
SCii Technologies
lior.a...@sncf.fr

Re:Bitmap.Assign causes memory leak ??


I have tested it and it does cause a leak. I've used System Monitor and
the allocated memory just grow's continiously if i use assign.
I'f i use something like Bitmap2.Draw(0,0,Bitmap1), it does not give
this continous growing of memory.

Is there some kind of compiler directive that must be set ??

Thanks
Conrad Smith

Quote
Lior Amar wrote:

> > should (will)  the above cause any memory leaks, if so why and how can i
> > correct it.
> > What happens to the memory allocated to the bitmap of the previous
> > image1.picture.bitmap when it is re-assigned top another bitmap.

> Have you checked if this gives a memory leak cause I have a hard time
> believing it will.  The only thing is that your Bitmap1 is still in memory.
> The free procedure is not ment to be used simply like that, at least not
> that I have seen it used like that.  If you check the value of Bitmap1 in
> the your watches I believe you'll still see a memory segment assigned to it,
> you need to add a Bitmap1 := nil to make sure it's released.

> For the second part, I would pretty much bet that when you assign an image
> to a previously assigned image it simply replaces them, I.E. the pointer now
> points to a different sector on the HD.  I might be wrong but I don't think
> your code will cause a leak, test it on several images and check to see if
> their is a leak.

> --
> Lior Amar
> Computer Consultant
> SCii Technologies
> lior.a...@sncf.fr

Re:Bitmap.Assign causes memory leak ??


Conrad:

Quote
Conrad Smith wrote in message <35A1E742.EFEDC...@icon.co.za>...
>while True do begin
>  Bitmap1:=TBitmap.Create;
>  Bitmap1.LoadFromFile('somebitmap.bmp');
>  Image1.Picture.Bitmap.Assign(Bitmap1);
>  Bitmap1.Free;
>end;

Instead of Assign above, I just use:

Image1.Picture.Graphic := Bitmap;

I haven't had any problems with this assignment.

efg
_________________________________________
efg's Computer Lab:  http://infomaster.net/external/efg

Earl F. Glynn                 E-Mail:  EarlGl...@att.net
MedTech Research Corporation, Lenexa, KS  USA

Re:Bitmap.Assign causes memory leak ??


I encountered something similar.  It turned out that a *palette* was
created/not freed.  I then abandoned the idea of continuously creating/freeing
and stuck with a bitmap that was large enough for my purposes.

Everything got freed when I exited the program.

Similar to your problem?

Joshua

Re:Bitmap.Assign causes memory leak ??


Yes it is similar, but unfortunately i can not get away without created
a bitmap each time, because im using a frame grabber card and need to
build a bitmap, using CreateDIBitmap, each time a new frame is captured.

And i need to use assign as to compare the current and previous frame
that is captured.

Any suggestions is welcome PLEASE !!!

Thanks
Conrad Smith

Quote
Xacc wrote:

> I encountered something similar.  It turned out that a *palette* was
> created/not freed.  I then abandoned the idea of continuously creating/freeing
> and stuck with a bitmap that was large enough for my purposes.

> Everything got freed when I exited the program.

> Similar to your problem?

> Joshua

Re:Bitmap.Assign causes memory leak ??


In article <35A1E742.EFEDC...@icon.co.za>,

Quote
  conrad.q...@icon.co.za wrote:
> I've encountered the following error and wonder if there may be a way
> around this

> lets say i have the following code

> Image1 : TImage; //which is displayed on screen

> Bitmap1 : TBitmap;

> while True do begin
>   Bitmap1:=TBitmap.Create;
>   Bitmap1.LoadFromFile('somebitmap.bmp');
>   Image1.Picture.Bitmap.Assign(Bitmap1);
>   Bitmap1.Free;
> end;

> should (will)  the above cause any memory leaks, if so why and how can i
> correct it.
> What happens to the memory allocated to the bitmap of the previous
> image1.picture.bitmap when it is re-assigned top another bitmap.

          Why do you say this is an "error"? What goes wrong, exactly?

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp   Create Your Own Free Member Forum

Other Threads