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
Responder
Avatar de Usuario
emeasoft
Mensajes: 1088
Registrado: Mié Abr 01, 2009 4:12 pm
Ubicación: emeasoft
Contactar:

TPicture:MakeThumbNail() consuming too much memory

Mensaje por emeasoft »

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:

Código: Seleccionar todo

  
  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:

Código: Seleccionar todo

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

André Corrêa
Avatar de Usuario
ignacio
Site Admin
Mensajes: 9246
Registrado: Lun Abr 06, 2015 8:00 pm
Ubicación: Madrid, Spain
Contactar:

Re: TPicture:MakeThumbNail() consuming too much memory

Mensaje por ignacio »

Hello,

Try something like this:

Código: Seleccionar todo

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]
https://www.xailer.com
Avatar de Usuario
emeasoft
Mensajes: 1088
Registrado: Mié Abr 01, 2009 4:12 pm
Ubicación: emeasoft
Contactar:

Re: TPicture:MakeThumbNail() consuming too much memory

Mensaje por emeasoft »

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
Avatar de Usuario
ignacio
Site Admin
Mensajes: 9246
Registrado: Lun Abr 06, 2015 8:00 pm
Ubicación: Madrid, Spain
Contactar:

Re: TPicture:MakeThumbNail() consuming too much memory

Mensaje por ignacio »

Hello,

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

Regards,
Adjuntos
iPicture.rar
(19.19 KiB) Descargado 205 veces
Ignacio Ortiz de Zúñiga
[Equipo de Xailer / Xailer team]
https://www.xailer.com
Avatar de Usuario
emeasoft
Mensajes: 1088
Registrado: Mié Abr 01, 2009 4:12 pm
Ubicación: emeasoft
Contactar:

Re: TPicture:MakeThumbNail() consuming too much memory

Mensaje por emeasoft »

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
Avatar de Usuario
ignacio
Site Admin
Mensajes: 9246
Registrado: Lun Abr 06, 2015 8:00 pm
Ubicación: Madrid, Spain
Contactar:

Re: TPicture:MakeThumbNail() consuming too much memory

Mensaje por ignacio »

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]
https://www.xailer.com
Avatar de Usuario
emeasoft
Mensajes: 1088
Registrado: Mié Abr 01, 2009 4:12 pm
Ubicación: emeasoft
Contactar:

Re: TPicture:MakeThumbNail() consuming too much memory

Mensaje por emeasoft »

Hi Ignacio,

The sample project is attached along with the image.

Thank you,

André Corrêa
Adjuntos
ThumbNailSample.zip
(148.85 KiB) Descargado 181 veces
Avatar de Usuario
ignacio
Site Admin
Mensajes: 9246
Registrado: Lun Abr 06, 2015 8:00 pm
Ubicación: Madrid, Spain
Contactar:

Re: TPicture:MakeThumbNail() consuming too much memory

Mensaje por ignacio »

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:

Código: Seleccionar todo

:LoadFromFile(Application:cDirectory+"IMG1.JPG", 1, .T.)
Regards,
Ignacio Ortiz de Zúñiga
[Equipo de Xailer / Xailer team]
https://www.xailer.com
Avatar de Usuario
emeasoft
Mensajes: 1088
Registrado: Mié Abr 01, 2009 4:12 pm
Ubicación: emeasoft
Contactar:

Re: TPicture:MakeThumbNail() consuming too much memory

Mensaje por emeasoft »

Hi,

I tried using GDI+, but unfortunately it did not solve the problem.
ThumbNail.png
ThumbNail.png (67.31 KiB) Visto 7307 veces
Thank you,

André Corrêa
Avatar de Usuario
ignacio
Site Admin
Mensajes: 9246
Registrado: Lun Abr 06, 2015 8:00 pm
Ubicación: Madrid, Spain
Contactar:

Re: TPicture:MakeThumbNail() consuming too much memory

Mensaje por ignacio »

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) Visto 7262 veces
9) The file, in case you want to test it yourself

https://dl.dropboxusercontent.com/u/318 ... Sample.exe

Regards,
Ignacio Ortiz de Zúñiga
[Equipo de Xailer / Xailer team]
https://www.xailer.com
Avatar de Usuario
emeasoft
Mensajes: 1088
Registrado: Mié Abr 01, 2009 4:12 pm
Ubicación: emeasoft
Contactar:

Re: TPicture:MakeThumbNail() consuming too much memory

Mensaje por emeasoft »

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
Avatar de Usuario
ignacio
Site Admin
Mensajes: 9246
Registrado: Lun Abr 06, 2015 8:00 pm
Ubicación: Madrid, Spain
Contactar:

Re: TPicture:MakeThumbNail() consuming too much memory

Mensaje por ignacio »

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]
https://www.xailer.com
Responder