Just looking at the start of the code, I can see the issue already. Let me highlight a few problems:
source_handle = _LOADIMAGE("logo.jpg", 32)
_PUTIMAGE (0, 0), source_handle, Page&
source_handle = _LOADIMAGE("disenofactura6.jpg", 32)
_PUTIMAGE (0, 261), source_handle, Page&
'CursorPosY = 570
PointSize = 12
IF copias = 2 THEN
_DEST Page&
source_handle = _LOADIMAGE("copia.png", 32)
How many times are you loading images here?
How many times are you freeing them?
When you do call _FREEIMAGE later, how is it supposed to free all those images whose handle you overwrote??
source_handle = _LOADIMAGE("logo.jpg", 32)
_PUTIMAGE (0, 0), source_handle, Page&
_FREEIMAGE source_handle
source_handle = _LOADIMAGE("disenofactura6.jpg", 32)
_PUTIMAGE (0, 261), source_handle, Page&
_FREEIMAGE source_handle
'CursorPosY = 570
PointSize = 12
IF copias = 2 THEN
_DEST Page&
source_handle = _LOADIMAGE("copia.png", 32)
Just because you're repurposing the variable you used to store your image handle, that doesn't mean you freed that image. Tell me what this would do:
source_handle = _LOADIMAGE("logo.jpg", 32)
source_handle = source_handle + 1
_FREEIMAGE source_handle
Our image handle might've been -10, but we changed our variable to make it -9, so either we just freed the wrong image, or else we simply did nothing as there was no image number -9 to free...
You have to free those images before you repurpose your variable, or else you're going to see that massive memory leak which you're describing in your code.