Recent

Author Topic: Out of heap  (Read 651 times)

BubikolRamios

  • Sr. Member
  • ****
  • Posts: 347
Out of heap
« on: January 12, 2025, 03:20:13 pm »
This is repeated x times until '0ut of heap' , I suspect "PaintBox1.canvas.Draw" line. Should be anything freed in process ?

Code: Pascal  [Select][+][-]
  1. var
  2.    image: TBGRABitmap;
  3. begin
  4.  
  5.       image := TBGRABitmap.Create(BitmapCopyFromForm1);    
  6.      
  7.       //... change of image ...
  8.      
  9.      PaintBox1.canvas.Draw(0,0,image.Bitmap);
  10.      
  11.      image.Free;        
  12. end;                  
  13.  

BitmapCopyFromForm1: Tbitmap; is created on form create and changed occasionally.
But for this post, think of it as not changed at all.
« Last Edit: January 12, 2025, 03:22:35 pm by BubikolRamios »
lazarus 3.2-fpc-3.2.2-win32/win64

jamie

  • Hero Member
  • *****
  • Posts: 6801
Re: Out of heap
« Reply #1 on: January 12, 2025, 05:24:33 pm »
I don't know that component that well, but my guess is you need to have local B:TBitmap that you can assign from the IMAGE.Bitmap;

use the local and then free the local before exiting the block.

The only true wisdom is knowing you know nothing

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 10799
  • Debugger - SynEdit - and more
    • wiki
Re: Out of heap
« Reply #2 on: January 12, 2025, 05:33:24 pm »
Your example has a lot of code missing. A lot of code that could "leak" (loose that memory)


Compile your app with "heaptrc" (-gh) => project options > Compiler settings > Debugging
Also make sure to include debug info (dwarf), and "display line numbers..." -gl

And make sure you also change the options of the bgra package to include debug info (dwarf).

Then run your app (on windows enable console). Check the console output of your app when it exists => most likely it will print stacktraces where memory was leaked. (allocated but never freed).

Lots of then entries will be nested, if your loose a bitmap then you loose all the stuff inside it too. So you need to search for the one in your code.

You can copy that output and paste it into => menu: view > leaks and traces

Thaddy

  • Hero Member
  • *****
  • Posts: 16520
  • Kallstadt seems a good place to evict Trump to.
Re: Out of heap
« Reply #3 on: January 12, 2025, 06:39:33 pm »
Out of heap means also basically out of memory, so for sure you need to free a lot.
I have never seen an out of heap error in 40 odd years, so concrats! you must be one of the first...and doing something very,very wrong, but we do not know what because your info is too scarse.
The heap size itself is usually available physical memory + the available swap space.
(this is not the case for embedded, where the heap can be explicitly defined, depending on system)
« Last Edit: January 12, 2025, 06:43:35 pm by Thaddy »
But I am sure they don't want the Trumps back...

BubikolRamios

  • Sr. Member
  • ****
  • Posts: 347
Re: Out of heap
« Reply #4 on: January 12, 2025, 07:53:17 pm »
moved to: https://forum.lazarus.freepascal.org/index.php/topic,69850.0.html

if nothing there, will go into Martin_fr advice (-:
« Last Edit: January 12, 2025, 07:56:47 pm by BubikolRamios »
lazarus 3.2-fpc-3.2.2-win32/win64

 

TinyPortal © 2005-2018