freeimage() needed before copyimage()

Just starting out? Need help? Post your questions and find answers here.
jassing
Addict
Addict
Posts: 1885
Joined: Wed Feb 17, 2010 12:00 am

freeimage() needed before copyimage()

Post by jassing »

Let's say #image1 is an image, but I issues CopyImage(#image2, #image1) --- is the memory automatically freed, or should I be calling freeimage 1st?
User avatar
Bisonte
Addict
Addict
Posts: 1320
Joined: Tue Oct 09, 2007 2:15 am

Re: freeimage() needed before copyimage()

Post by Bisonte »

Clean programming means: If you take something, you give it back when it is no longer needed.

A programming language cannot see into the programmer's head to guess what he is going to do next.

But in this case : If #Image1 is a fixed number (and not created with #PB_Any) then it is released.

At least that's what everyone has said so far...

(translated by DeepL.com)
PureBasic 6.21 (Windows x64) | Windows 11 Pro | AsRock B850 Steel Legend Wifi | R7 9800x3D | 64GB RAM | RTX 5080 | ThermaltakeView 270 TG ARGB | build by vannicom​​
English is not my native language... (I often use DeepL.)
boddhi
Enthusiast
Enthusiast
Posts: 524
Joined: Mon Nov 15, 2010 9:53 pm

Re: freeimage() needed before copyimage()

Post by boddhi »

Hello,

Code: Select all

Enumeration
  #image1
  #Image2
EndEnumeration

; Example 1 : When #Image2 doesn't exist
CreateImage(#image1,50,50)
CopyImage(#image1,#Image2)
Debug IsImage(#Image2)

; Example 2 : When #Image2 already exists
ResizeImage(#Image2,1,1)
CopyImage(#image1,#Image2)
Debug IsImage(#Image2)
If my English syntax and lexicon are incorrect, please bear with Google translate and DeepL. They rarely agree with each other!
Except on this sentence...
User avatar
mk-soft
Always Here
Always Here
Posts: 6320
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: freeimage() needed before copyimage()

Post by mk-soft »

PB-Help: https://www.purebasic.com/documentation ... jects.html
- An object that is associated with an index is automatically freed when reusing that index.
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
jassing
Addict
Addict
Posts: 1885
Joined: Wed Feb 17, 2010 12:00 am

Re: freeimage() needed before copyimage()

Post by jassing »

Bisonte wrote: Wed May 29, 2024 7:31 am Clean programming means: If you take something, you give it back when it is no longer needed.
Yes, I understand that. Yet, purebasic does some things "automatically" ... I realized I hadn't free'd the images, and wondered if I needed to go back into the code and change it. I don't regularly work with images... I was hoping copyimage would free the destination if it exists.
Bisonte wrote: Wed May 29, 2024 7:31 am A programming language cannot see into the programmer's head to guess what he is going to do next.
However, if you're copying #iamge1 to #image2 - the language could know #image2 is no longer needed.
Last edited by jassing on Wed May 29, 2024 12:25 pm, edited 1 time in total.
jassing
Addict
Addict
Posts: 1885
Joined: Wed Feb 17, 2010 12:00 am

Re: freeimage() needed before copyimage()

Post by jassing »

mk-soft wrote: Wed May 29, 2024 8:25 am PB-Help: https://www.purebasic.com/documentation ... jects.html
- An object that is associated with an index is automatically freed when reusing that index.
Thank you.
Post Reply