Recent

Author Topic: LazPaint and "Out of Memory" Errors.  (Read 26463 times)

DelphiFreak

  • Sr. Member
  • ****
  • Posts: 255
    • Fresh sound.
LazPaint and "Out of Memory" Errors.
« on: July 12, 2011, 04:02:22 am »
I am getting all the time "Out of Memory" Error with Lazarus and the "Select" "Magic Wand" function.

How to reproduce:
1.) Load a photo.
2.) Use 2-4 times (depends on the amount of memory on your computer) the function "Select"->"Magic Wand"

Crash.

I have reported this problem at
https://sourceforge.net/tracker/index.php?func=detail&aid=3353939&group_id=404555&atid=1676204

Does  anyone else have the same problem?
Linux Mint 20.3, Lazarus 2.3, Windows 10, Delphi 10.3 Rio, Delphi 11.1 Alexandria

lainz

  • Guest
Re: LazPaint and "Out of Memory" Errors.
« Reply #1 on: July 12, 2011, 04:09:29 am »
Works fine for me using LazPaint svn 257 Lazarus 0.9.31 r31661 FPC 2.4.4 i386-win32-win32/win64

1.5gb ram, Windows7.

Edit: I've opened a photo of 4000x3000 px and the magic wand works.

Edit2: If I use the magic wand 40 or more times the application get blocked, the amount of memory used is 941.000kb in the Task Administrator of Windows.
« Last Edit: July 12, 2011, 04:17:49 am by lainz »

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4459
  • I like bugs.
Re: LazPaint and "Out of Memory" Errors.
« Reply #2 on: July 12, 2011, 12:28:31 pm »
You should use heaptrc (-gh) option when building LazPaint. It will tell you where the memory leak is.
Using all possible checks provided by FPC is a good idea when testing SW.

Juha
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

DirkS

  • Sr. Member
  • ****
  • Posts: 251
Re: LazPaint and "Out of Memory" Errors.
« Reply #3 on: July 12, 2011, 12:48:53 pm »
You should use heaptrc (-gh) option when building LazPaint. It will tell you where the memory leak is.
Using all possible checks provided by FPC is a good idea when testing SW.
Absolutely true...

Just for fun I did this for LazPaint and just starting and stopping the program results in 2 unfreed blocks:
Quote
Heap dump by heaptrc unit
31757 memory blocks allocated : 3038053/3130432
31755 memory blocks freed     : 3037935/3130304
2 unfreed memory blocks : 118
True heap size : 491520 (112 used in System startup)
True free heap : 491360
Should be : 491152
Call trace for block $00087730 size 59
  $00444A2A  TLAZPAINTCONFIG__INITRECENTFILES,  line 411 of uconfig.pas
  $00444F80  TLAZPAINTCONFIG__CREATE,  line 466 of uconfig.pas
  $00435A4F  TLAZPAINTINSTANCE__USECONFIG,  line 239 of lazpaintinstance.pas
  $00402E6A  main,  line 61 of lazpaint.lpr
  $00411621
  $0043567E  TLAZPAINTINSTANCE__INIT,  line 177 of lazpaintinstance.pas
  $004356FE  TLAZPAINTINSTANCE__CREATE,  line 182 of lazpaintinstance.pas
  $00402DFD  main,  line 59 of lazpaint.lpr
Call trace for block $00087610 size 59
  $00444A2A  TLAZPAINTCONFIG__INITRECENTFILES,  line 411 of uconfig.pas
  $00444F80  TLAZPAINTCONFIG__CREATE,  line 466 of uconfig.pas
  $00435A4F  TLAZPAINTINSTANCE__USECONFIG,  line 239 of lazpaintinstance.pas
  $0043567E  TLAZPAINTINSTANCE__INIT,  line 177 of lazpaintinstance.pas
  $004356FE  TLAZPAINTINSTANCE__CREATE,  line 182 of lazpaintinstance.pas
  $00402DFD  main,  line 59 of lazpaint.lpr
  $00411621
  $00421841  TAPPLICATION__SMALLICONHANDLE,  line 1125 of ./include/application.inc

Edit: it looks as if the recentFiles stringlist does not get freed...

Gr.
Dirk.
« Last Edit: July 12, 2011, 01:04:09 pm by DirkS »

lainz

  • Guest
Re: LazPaint and "Out of Memory" Errors.
« Reply #4 on: July 12, 2011, 03:34:21 pm »
Is possible to save the headptrc head dump to a text file?

DirkS

  • Sr. Member
  • ****
  • Posts: 251
Re: LazPaint and "Out of Memory" Errors.
« Reply #5 on: July 12, 2011, 04:27:03 pm »
Is possible to save the headptrc head dump to a text file?
Under windows: if you make it a non-gui app and start lazpaint from the command line the heap trace will also be written to the command window.
Either grab it from there or redirect the output to a file.

There's probably other ways to do the same.

Gr.
Dirk.

garlar27

  • Hero Member
  • *****
  • Posts: 652
Re: LazPaint and "Out of Memory" Errors.
« Reply #6 on: July 12, 2011, 04:54:30 pm »
You can use something like this in your .lpr :
Code: [Select]
     if FileExists('_heap.txt') then
       DeleteFile('_heap.txt');
     SetHeapTraceOutput('_heap.txt');

Also, you can install LeakView component, it's very usefull.

lainz

  • Guest
Re: LazPaint and "Out of Memory" Errors.
« Reply #7 on: July 12, 2011, 06:49:55 pm »
Thanks to all  :)

circular

  • Hero Member
  • *****
  • Posts: 4195
    • Personal webpage
Re: LazPaint and "Out of Memory" Errors.
« Reply #8 on: July 16, 2011, 03:05:01 pm »
You're right that much memory is used, but this is because of the undo history. There is a way to use less memory here, by using a differential undo, i.e., storing the XOR of two consecutive images in the history.
Conscience is the debugger of the mind

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: LazPaint and "Out of Memory" Errors.
« Reply #9 on: July 16, 2011, 03:15:51 pm »
Erm, there's a difference between using (a lot or a tiny bit, doesn't matter) of memory and then releasing it properly, or using memory and not releasing it.
The latter is called a memory leak  :)

(Sorry for the sarcastic tone, don't take it personally, I'm just in a grumpy mood today  >:D)
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

circular

  • Hero Member
  • *****
  • Posts: 4195
    • Personal webpage
Re: LazPaint and "Out of Memory" Errors.
« Reply #10 on: July 16, 2011, 06:18:53 pm »
BigChimp, we're not going to create a new topic for each subtle difference between subjects. A memory leak can be the cause of an "out of memory" error.
Conscience is the debugger of the mind

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: LazPaint and "Out of Memory" Errors.
« Reply #11 on: July 16, 2011, 06:46:37 pm »
Hi Circular,

Might have misunderstood you. Yes, a memory leak IS probably the cause of an out of memory error. My point is that chances of a memory error/problem occurring if there isn't a leak is slimmer because of bigger RAM sizes and the possible use of a swap/page file....

--- Edited: memory=>memor leak. Fortunately Circular understood what I meant...
« Last Edit: July 17, 2011, 04:38:43 pm by BigChimp »
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

circular

  • Hero Member
  • *****
  • Posts: 4195
    • Personal webpage
Re: LazPaint and "Out of Memory" Errors.
« Reply #12 on: July 17, 2011, 04:07:57 pm »
I agree. However, when working with a big image, saving copies of it can rapidly lead to high memory usage. So if there is a problem with the memory manager or no more disk space available, it is possible to get an "out of memory" error. On the other side, there does not seem to be a memory leak here, and the program works on many systems, so "normal" high memory usage is probable here.
Conscience is the debugger of the mind

lainz

  • Guest
Re: LazPaint and "Out of Memory" Errors.
« Reply #13 on: July 25, 2011, 04:58:38 pm »
I agree. However, when working with a big image, saving copies of it can rapidly lead to high memory usage. So if there is a problem with the memory manager or no more disk space available, it is possible to get an "out of memory" error. On the other side, there does not seem to be a memory leak here, and the program works on many systems, so "normal" high memory usage is probable here.

I remember that Corel Photo Paint has options for memory usage:
* The amount of undo-redo history (up to 99)
* The amount of memory (% of memory limit)
* The amount of disk space / disk drives the app can use

Also PP is really fast in mask usage.

circular

  • Hero Member
  • *****
  • Posts: 4195
    • Personal webpage
Re: LazPaint and "Out of Memory" Errors.
« Reply #14 on: July 26, 2011, 08:58:13 pm »
On svn, I've commited a new version, that works with last bgrabitmap (4.7), which uses xor to use less disk space.

But you're right, some options could be useful. Maybe we can wait if there are more options, and then think about creating some option dialog.
Conscience is the debugger of the mind

 

TinyPortal © 2005-2018