Author Topic: MEMORY LEAK problem using _LOADIMAGE  (Read 4645 times)

0 Members and 1 Guest are viewing this topic.

Offline EricE

  • Forum Regular
  • Posts: 114
    • View Profile
Re: MEMORY LEAK problem using _LOADIMAGE
« Reply #15 on: February 25, 2020, 01:11:11 pm »
As SMcNeill points out it is always good practice to check the function return value.
Here is the second program with error checking and error message output added.

Image used is again that of the IBM 704. ("Now THAT was a computer!")

Code: QB64: [Select]
  1. version$ = "Memory_leak_FORUM-2'.bas"
  2.  
  3. '       insert YOUR very large picture file here
  4. image$ = "IBM_Electronic_Data_Processing_Machine_-_GPN-2000-001881.bmp"
  5. '                       "D:\Dit.bmp" is my test .bmp file (~ 16 Mbyte)
  6.  
  7. count& = 1000000 '           number of _Loadimage(image$) to be tried
  8.  
  9. xxmax% = 1024
  10. yymax% = 600
  11. SCREEN _NEWIMAGE(xxmax%, yymax%, 32) 'use a part of the total display
  12. image% = 512 '                        displayed (square) picture size
  13.  
  14. lastline% = 25
  15. VIEW PRINT 1 TO lastline%
  16. LOCATE lastline%, 1: PRINT "abc" '                    simple text task
  17. LINE (0, 0)-(xxmax%, yymax%), &HFF80FF80& '       simple graphics task
  18.  
  19. FOR i& = 1 TO count&
  20.     image& = _LOADIMAGE(image$) ' image to be loaded
  21.     IF image& < -1 THEN
  22.         _PUTIMAGE (xxmax% - image%, 0)-(xxmax%, image%), image&
  23.         LOCATE lastline%, 50
  24.         PRINT USING "#,###,###"; i&; '           simple update of text task
  25.  
  26.         _FREEIMAGE image&
  27.         image& = 0 '         checked to free old image, if it existed
  28.     ELSE
  29.         ' Image load error handler or notification code here
  30.         LOCATE lastline% - 2, 1
  31.         PRINT "Error loading image "; i&;
  32.     END IF
  33. NEXT i&
  34.  


Offline Richard

  • Seasoned Forum Regular
  • Posts: 364
    • View Profile
Re: MEMORY LEAK problem using _LOADIMAGE
« Reply #16 on: February 25, 2020, 02:18:18 pm »
Thanks Steve and Eric

I have been running my "Slide Projector Program" now for a number of hours - started at the end of my last reply. It has cycled through 16,010 images (without a hitch) and is still going! Task Manager is oscillating around   77 to 96 Mbyte    and over all this time had extremely slowly "creeped"  to the 86 to 96 Mbyte   range. The images (.jpg) typically ranged in size from  10 KB to ~ 200KB.

I inserted Steve's  "handle <-1 etc check".

Before I started this topic, my Slide Projector Program resulted in the need for the following code fragments :-




            ON ERROR GOTO Errhandler '         ********************************************

~~~~~~~~~
eror_258% = 0  '         reset  error # 258 flag
GOSUB PUT_image
~~~~~~~~~


Errhandler:
eror% = -1

SELECT CASE ERR
    CASE 258: eror_258% = -1 '  _Putimage    invalid handle
    CASE 5::: eror_005% = -1: ' '  _FreeImage   illegal function call
    CASE ELSE: BEEP: BEEP: BEEP
END SELECT
RESUME NEXT ' moves program to code following the error
RETURN



PUT_image:
img& = _LOADIMAGE(img$)
_PUTIMAGE (x0%, y0%)-(x1%, y1%), img& '   512x512 image TRHC
IF img& < -1 THEN _FREEIMAGE img&: img& = 0'                                    Steve's suggestion inserted here

StopWatch& = TIMER
IF NOT (eror_258%) THEN
    StopWatchSET& = TIMER
END IF
IF (StopWatch& - StopWatchSET&) > StopWatchMax& THEN GOTO BEEPsystemEND  ' just BEEP : SYSTEM: END

RETURN


The SYSTEM command may not be needed.
The Stopwatch code was handy for automatic shutdown. In my case the timeout was preset to 3 minutes since last VALID image.
The  handle (img& <-1) etc as suggested by Steve was inserted.

ERROR #258 frequently occurred with my very old images - say roughly 1% were well and truly corrupted which neither _PUTIMAGE or windows PAINT, etc could do anything with   -   and say roughly 1% _PUTIMAGE cannot (as the program was written) do anything BUT are viewable in Windows PAINT, PHOTOS, and just about any other commercial viewer app CAN display - the remaining 98% were well behaved.


Many thanks.


By the way Eric  - where does one insert the USB memory stick on the IBM  and more importantly where is the display?



For those curious to know   -   Slide projector program (1st run) STILL RUNNING   -  37,038 images (1.40 GB) processed,  time elapsed ~ 14.5 hours (if my time calculations are correct),  Task Manager oscillating    85 - 88 MB (ocassionally up to 95 MB) and no trending now easily visible --- program did not timeout or anything  --- PROGRAM STILL CONTINUOUSLY RUNNING without intervention.

For those curious to know - Slide Projector Program (1st run) - 58,241 images (2.15 GB) processed, time elapsed ~23 hours, Task Manager 84-89 MB oscillating (final value 84.2) no observable trend --- PROGRAM terminated by me.

No more updates!
« Last Edit: February 26, 2020, 07:39:37 am by Richard »