freeimage() needed before copyimage()
Posted: Wed May 29, 2024 6:02 am
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?
http://www.purebasic.com
https://www.purebasic.fr/english/
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)
- An object that is associated with an index is automatically freed when reusing that index.
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 Clean programming means: If you take something, you give it back when it is no longer needed.
However, if you're copying #iamge1 to #image2 - the language could know #image2 is no longer needed.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.
Thank you.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.