In order for this site to work correctly we need to store a small file (called a cookie) on your computer. Most every site in the world does this, however since the 25th of May 2011, by law we have to get your permission first. Please abandon the forum if you disagree.

Para que este foro funcione correctamente es necesario guardar un pequeño fichero (llamado cookie) en su ordenador. La mayoría de los sitios de Internet lo hacen, no obstante desde el 25 de Marzo de 2011 y por ley, necesitamos de su permiso con antelación. Abandone este foro si no está conforme.

TPicture:MakeThumbNail() consuming too much memory

Xailer professional forum in English
User avatar
emeasoft
Posts: 1062
Joined: Wed Apr 01, 2009 4:12 pm
Location: emeasoft
Contact:

TPicture:MakeThumbNail() consuming too much memory

Postby emeasoft » Tue Sep 06, 2016 5:37 pm

Hi,

Using the TPicture:MakeThumbNail() method inside a loop, we noticed that it was consuming
too much memory. Even calling one of the destructors, :END(), :DESTROY() or FREE() in each
iteration, it was not releasing the allocated memory.
As we were dealing with 12 thousand images, the method consumed 8GB RAM quickly.
Using the function CreateThumbNail(), this did not happen.

Sample codes:

Did not work:

Code: Select all

 
  DO WHILE i < 10000
    WITH OBJECT o01 := TPicture():Create()
      :LoadFromFile("C:\IMG1.JPG")
      :MakeThumbnail( :nWidth, :nHeight)
      :End()
      //:Destroy() or :Free() did not work too
    END
    i++
  ENDDO


Worked:

Code: Select all

  DO WHILE i < 10000
      CreateThumbnail(HB_MemoRead("C:\IMG1.JPG"))
    i++
  ENDDO


Thanks,

André Corrêa
User avatar
ignacio
Site Admin
Posts: 8546
Joined: Mon Apr 06, 2015 8:00 pm
Location: Madrid, Spain
Contact:

Re: TPicture:MakeThumbNail() consuming too much memory

Postby ignacio » Tue Sep 06, 2016 6:33 pm

Hello,

Try something like this:

Code: Select all

FOR EACH cFile IN aFiles
   WITH OBJECT TPicture():Create()
      :LoadFromFile( cFile,, .t. )
      cStream := :MakeThumbnail( nWidth, nWidth )
      cTarget := FilenameTakeOffExt( cFile )  + "_tn.jpg"
      HB_MemoWrit( cTarget, cStream, .f. )
      :End()
   END WITH
NEXT


Note: Function FilenameTakeOffExt() does not exist. It's mean to be used as pseudo code.

The demo program JPGREDUCER http://www.xailer.com/download?en&file=117 on our download area uses that code and does not have any memory leak.

Regards,
Ignacio Ortiz de Zúñiga
[Equipo de Xailer / Xailer team]
http://www.xailer.com
http://www.xailer.info
User avatar
emeasoft
Posts: 1062
Joined: Wed Apr 01, 2009 4:12 pm
Location: emeasoft
Contact:

Re: TPicture:MakeThumbNail() consuming too much memory

Postby emeasoft » Tue Sep 06, 2016 8:18 pm

Ignacio,

First, thank you for the reply.

The code I posted was only an example to simulate the big number of images.
I tried the demo program JPGREDUCER and it really does not causes any memory leak.
But using the same code in a test project, and compiling under Windows 10 - 64 bits, does.
It seems that the objects created are not destroyed or realeased from memory.

Regards,

André Corrêa
User avatar
ignacio
Site Admin
Posts: 8546
Joined: Mon Apr 06, 2015 8:00 pm
Location: Madrid, Spain
Contact:

Re: TPicture:MakeThumbNail() consuming too much memory

Postby ignacio » Tue Sep 06, 2016 9:02 pm

Hello,

Please try including the module attached: .o for MinGw and .obj for Borland.

Regards,
Attachments
iPicture.rar
(19.19 KiB) Downloaded 44 times
Ignacio Ortiz de Zúñiga
[Equipo de Xailer / Xailer team]
http://www.xailer.com
http://www.xailer.info
User avatar
emeasoft
Posts: 1062
Joined: Wed Apr 01, 2009 4:12 pm
Location: emeasoft
Contact:

Re: TPicture:MakeThumbNail() consuming too much memory

Postby emeasoft » Thu Sep 08, 2016 1:11 pm

Good morning,

I Tried to include the IPicture.o to the test project, recompiled it all, but it still not
releasing the allocated memory.

Thanks,

André Corrêa
User avatar
ignacio
Site Admin
Posts: 8546
Joined: Mon Apr 06, 2015 8:00 pm
Location: Madrid, Spain
Contact:

Re: TPicture:MakeThumbNail() consuming too much memory

Postby ignacio » Thu Sep 08, 2016 5:04 pm

Hello,

I suggest you send us a really small sample that we can test. Including the picture file your are using. TIA.

Regards,
Ignacio Ortiz de Zúñiga
[Equipo de Xailer / Xailer team]
http://www.xailer.com
http://www.xailer.info
User avatar
emeasoft
Posts: 1062
Joined: Wed Apr 01, 2009 4:12 pm
Location: emeasoft
Contact:

Re: TPicture:MakeThumbNail() consuming too much memory

Postby emeasoft » Mon Sep 12, 2016 2:04 pm

Hi Ignacio,

The sample project is attached along with the image.

Thank you,

André Corrêa
Attachments
ThumbNailSample.zip
(148.85 KiB) Downloaded 41 times
User avatar
ignacio
Site Admin
Posts: 8546
Joined: Mon Apr 06, 2015 8:00 pm
Location: Madrid, Spain
Contact:

Re: TPicture:MakeThumbNail() consuming too much memory

Postby ignacio » Mon Sep 12, 2016 5:03 pm

Hello,

I'm not able to reproduce your problem. I've tested with Xailer 4 binaries but is working fine here. Maybe its related to the version of the library FreeImage.DLL. In any case, is better to use GDI+, is faster and you do not need an external DLL:

Code: Select all

:LoadFromFile(Application:cDirectory+"IMG1.JPG", 1, .T.)


Regards,
Ignacio Ortiz de Zúñiga
[Equipo de Xailer / Xailer team]
http://www.xailer.com
http://www.xailer.info
User avatar
emeasoft
Posts: 1062
Joined: Wed Apr 01, 2009 4:12 pm
Location: emeasoft
Contact:

Re: TPicture:MakeThumbNail() consuming too much memory

Postby emeasoft » Mon Sep 12, 2016 9:30 pm

Hi,

I tried using GDI+, but unfortunately it did not solve the problem.

ThumbNail.png
ThumbNail.png (67.31 KiB) Viewed 3475 times


Thank you,

André Corrêa
User avatar
ignacio
Site Admin
Posts: 8546
Joined: Mon Apr 06, 2015 8:00 pm
Location: Madrid, Spain
Contact:

Re: TPicture:MakeThumbNail() consuming too much memory

Postby ignacio » Tue Sep 13, 2016 11:01 am

Hello,

I have just do the following:

1) Create a new Virtual Machine with Windows 10
2) Install Xailer 4.02 and Harbour binaries from our web site
3) Register the product
4) Open your proyect
5) Modify a little so I can see the current interaction
6) Create the EXE file
7) Test the consumption of memory
8) The result after 10.000 operations:
2016-09-13 10_58_12-Administrador de tareas.png
2016-09-13 10_58_12-Administrador de tareas.png (33.23 KiB) Viewed 3430 times

9) The file, in case you want to test it yourself

https://dl.dropboxusercontent.com/u/31888702/Xailer/ThumbNailSample.exe

Regards,
Ignacio Ortiz de Zúñiga
[Equipo de Xailer / Xailer team]
http://www.xailer.com
http://www.xailer.info
User avatar
emeasoft
Posts: 1062
Joined: Wed Apr 01, 2009 4:12 pm
Location: emeasoft
Contact:

Re: TPicture:MakeThumbNail() consuming too much memory

Postby emeasoft » Tue Sep 27, 2016 1:23 pm

Good morning,

Sorry for the delay.
I tested the sample you provided and it does work well.
Anyway, you sent only the exe and it not explains why the code I posted
and the sample I sent doesn't work.
If anyone else could test it, would be a great help.

TIA,

André Corrêa
User avatar
ignacio
Site Admin
Posts: 8546
Joined: Mon Apr 06, 2015 8:00 pm
Location: Madrid, Spain
Contact:

Re: TPicture:MakeThumbNail() consuming too much memory

Postby ignacio » Tue Sep 27, 2016 3:58 pm

Hello,

You already have the code. Is indeed you code with few lines more.

Please reread my message. I believe is quite clear how I made the test using a complete brand and new version of Xailer 4 downloaded directly from our web site and Windows 10. Please consider to do EXACTLY the same I did.

Regards,
Ignacio Ortiz de Zúñiga
[Equipo de Xailer / Xailer team]
http://www.xailer.com
http://www.xailer.info

Return to “English”