I have a global array of pictures that remains in memory while the app is running and this array has some pictures added to it which are created on the fly (with p = New Picture and array.append p etc) and others which are simply references to images dragged into the project (i.e. array.append image1).
Is it okay to add references to the same image resource each time within the same array or should I always create a new picture object and draw the image resource to that new picture object?
I’m guessing it’s actually saving on memory to just use the reference but wanted to make sure I wasn’t doing something considered “bad practice” and causing myself some kind of circular reference problem.
(assuming I have dragged an image resource into the project called “image1” and myArray is a global array.
Dim p, pic As Picture
myArray.append image1
p = New Picture(image1.width, image1.height,32)
p.graphics.forecolor = rgb(0,0,0)
p.graphics.fillrect 0,0,p.width,p.height
myArray.append p
pic = image1
myArray.append pic
pic = p
myArray.append pic
myArray.append p
p.graphics.forecolor = rgb(50,50,50)
p.graphics.fillrect 0,0,p.width,p.height
myArray.append p
pic = p
myArray.append pic
What happens if I have referenced p by assigning its value to pic and then change p?
Does the instance of pic in the array change too?
Or does the picture appended to the array remain in the same state it was in when it was added?
You have a total of 2 images, one of which started as a black rectangle which you then turned into a gray rectangle. Your array contains the following references
And note that the values in the array didn’t change. They’re all separate references to the same object (a picture), the attributes of which did change.