Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Free all images? (Pic.New/Pic.Free)
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
fiercedeity




PostPosted: Sat Jun 03, 2017 4:15 pm   Post subject: Free all images? (Pic.New/Pic.Free)

What is it you are trying to achieve?
Turing provides no way to completely restart the execution of a program's code (that I know of, PLEASE correct me, if I'm wrong!), so I've decided to use loops and Window.Open/Window.Close to fake the restarting of the program. However, this won't free the images that I previously created using Pic.New.
I need to be able to free all of images previously created so the program stays under Turing's 1000 image-limit.


Describe what you have tried to solve this problem
I tried/was thinking of using Pic.Free (), but ...


What is the problem you are having?
Pic.Free (), in addition to only being able to free one image at a time, does not free images that used the same variable, but have since been replaced (see example code below). So I really need some way to cleanse ALL the image "ID"s.


Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
Not my code, but essentially the problem:

image1 := Pic.Scale (image1, x, y)
image1 := Pic.Mirror (image1)

^ various commands like these are repeated a number of times throughout the code; the same variables are getting reused.

Please specify what version of Turing you are using
Turing 4.1
Sponsor
Sponsor
Sponsor
sponsor
Jynx101




PostPosted: Sat Jun 03, 2017 9:15 pm   Post subject: RE:Free all images? (Pic.New/Pic.Free)

Perhaps you have the order of the code wrong? Pic.Free should work.

Pic.Free should go first when putting out the image

var background := Pic.FileNew ("Image.bmp")

Pic.Free (Image)
background := Pic.FileNew ("Image.bmp")
Pic.Draw (background 0, 0, picMerge)

And I'm assuming when you say "restart the execution", you're saying that you need to re-run that little section of your program. Why not use a procedure and have a go?
Insectoid




PostPosted: Sun Jun 04, 2017 7:09 am   Post subject: RE:Free all images? (Pic.New/Pic.Free)

No programming language I know of has any method of completely restarting execution from scratch. That is an OS-level operation. However, Turing does have the capability to launch programs, including itself, with the Sys.Exec command. Use Sys.Exec to launch a new instance of the program, then have the program terminate itself. This method will only work if you generate a stand-alone executable, and will fail if you ever re-name the program file. For that reason, I do not recommend it.

If you are re-assigning image variables with Pic.FileNew without first calling Pic.Free, the old images are still loaded in memory, but there is no way to access them and they cannot be freed. You must manually free each image before re-assigning the variable.

The easiest way to keep your images under control is to free them as soon as they are no longer needed. Do not re-use variables with Pic.scale etc. I suggest you use a set of disposable variables for loading/manipulating images and only use the 'real' image variable for the final image.
fiercedeity




PostPosted: Sun Jun 04, 2017 4:32 pm   Post subject: Re: Free all images? (Pic.New/Pic.Free)

Okay. Thanks for the tips!!
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 4 Posts ]
Jump to:   


Style:  
Search: