Recent

Author Topic: Out of memory / filter twirl  (Read 735 times)

BubikolRamios

  • Sr. Member
  • ****
  • Posts: 347
Out of memory / filter twirl
« on: January 12, 2025, 07:52:33 pm »
Besides end out of memory, looking at task manager, how it eats memory.

Can't seem to find in lazpaint, what is there different, if anything at all.

Replace 1002.bmp with any inside project folder

Code: Pascal  [Select][+][-]
  1.  var
  2.    image: TBGRABitmap;
  3.    Dest: TRect;
  4.    point: TPoint;
  5.  
  6. begin
  7.   while 1 = 1 do
  8.   begin
  9.  
  10.   try
  11.  
  12.       image := TBGRABitmap.Create(ExtractFilePath(ParamStr(0))  + '\1002.bmp');
  13.       Dest.Height:= image.Height;
  14.       Dest.Width:= image.Width;
  15.       point.X := round(image.Width/2);
  16.       point.Y := round(image.Height/2);
  17.        
  18.       //comment next line and there will be no leak
  19.      // also note, if ' image := ' removed, also something is happening, and also memory leaking, less, but leaking
  20.       image := image.FilterTwirl(Dest,point,image.Height,1,3);
  21.  
  22.   finally
  23.     image.Free;
  24.  
  25.   end;
  26.  
  27.  
  28.   end;
  29. end;  
  30.  
« Last Edit: January 12, 2025, 07:55:25 pm by BubikolRamios »
lazarus 3.2-fpc-3.2.2-win32/win64

jamie

  • Hero Member
  • *****
  • Posts: 6801
Re: Out of memory / filter twirl
« Reply #1 on: January 12, 2025, 08:00:33 pm »
What is it with you?

Those functions return a newly created bitmap which you must free.

In this example, you overwrote the first IMAGE with a new Image, now the first image is sitting in limbo.

Please use separate images and free both the original and the newly created.

The only true wisdom is knowing you know nothing

BubikolRamios

  • Sr. Member
  • ****
  • Posts: 347
Re: Out of memory / filter twirl
« Reply #2 on: January 12, 2025, 08:03:09 pm »
What is it with you?

Those functions return a newly created bitmap which you must free.

In this example, you overwrote the first IMAGE with a new Image, now the first image is sitting in limbo.

Please use separate images and free both the original and the newly created.

what did I said ?

Code: Pascal  [Select][+][-]
  1. image.FilterTwirl(Dest,point,image.Height,1,3);
  2.  

Gets out of memory also. Doesn't then all gets free ?
And even if that creates something somewhere in empty space, one should expect some kind of error ?

Thought you are right, with new Image.
« Last Edit: January 12, 2025, 08:28:27 pm by BubikolRamios »
lazarus 3.2-fpc-3.2.2-win32/win64

Thaddy

  • Hero Member
  • *****
  • Posts: 16520
  • Kallstadt seems a good place to evict Trump to.
Re: Out of memory / filter twirl
« Reply #3 on: January 12, 2025, 08:30:48 pm »
You are creating the image twice, causing the first instance to be dangling.
Don't you see that yourself?

You free it only once. Of course that is a massive leak.
At least you smelled it yourself, so you know you are wrong:
Code: Pascal  [Select][+][-]
  1.  //comment next line and there will be no leak
  2.      // also note, if ' image := ' removed, also something is happening, and also memory leaking, less, but leaking
  3.       image := image.FilterTwirl(Dest,point,image.Height,1,3);
That is creating twice.

 
« Last Edit: January 12, 2025, 08:32:29 pm by Thaddy »
But I am sure they don't want the Trumps back...

BubikolRamios

  • Sr. Member
  • ****
  • Posts: 347
Re: Out of memory / filter twirl
« Reply #4 on: January 12, 2025, 08:32:02 pm »
See it now, not everyday in pascal.
lazarus 3.2-fpc-3.2.2-win32/win64

circular

  • Hero Member
  • *****
  • Posts: 4383
    • Personal webpage
Re: Out of memory / filter twirl
« Reply #5 on: January 14, 2025, 05:53:52 pm »
Please be nice with people asking questions.

BubikolRamios, indeed when assigning directly the new image, the previous pointer is not freed. You can do that in a short way by using BGRAReplace function.
Conscience is the debugger of the mind

Thaddy

  • Hero Member
  • *****
  • Posts: 16520
  • Kallstadt seems a good place to evict Trump to.
Re: Out of memory / filter twirl
« Reply #6 on: January 14, 2025, 07:23:20 pm »
Please be nice with people asking questions.
OP understood I was trying to help.
But I am sure they don't want the Trumps back...

 

TinyPortal © 2005-2018