Hi Alexandre
See this is from long ago.
This is execatly the same issue you had I think.
Just test what you were doing and your are right that works.
Here is the code
dim p as picture
dim colorPixel as Color
for i as integer = 0 to 10
f = new FolderItem("../Large/image.jpg",FolderItem.PathTypeShell) // just reference any file in you environment
dim myRGB as RGBSurface
if f <> Nil then
p = Picture.Open(f)
//myRGB = p.RGBSurface // If I omit this line, no Reference build up, no memory leak
//colorPixel = myRGB.Pixel(1,1) // This also together with the previous line is the culprit.
colorPixel = p.Graphics.Pixel(1,1) // This is how you did it, and then no reference build up....
Print("****************** next file ****************")
Print ("Object Count: " + Runtime.ObjectCount.ToText + " Using memory : " + Runtime.MemoryUsed.ToText)
dim L as Integer = Runtime.ObjectCount -1
for k as integer = 0 to L
Print("ObjectID: " + Runtime.ObjectId(k).ToText + " Class: " + Runtime.ObjectClass(k).ToText + " Refs: " + Runtime.ObjectRefs(k).ToText)
next
end if
p = nil
myRGB = nil
next i
end if
If you change this back to the following
myRGB = p.RGBSurface // If I omit this line, no Reference build up, no memory leak
colorPixel = myRGB.Pixel(1,1)
// colorPixel = p.Graphics.Pixel(1,1)
This just stacks up additional memory and never release it until the end of the program
Doing this in the console. I was initially running it over many files, and they are large 2500x2500. Quickly running into GB and the program fails. I then narrowed it down to this one statement. The rest of the program is a reduced version fo my code.
So the answers here were never addressing this issue.
You do not even have to do a pixel inspect. You just have to assign anything from the RGBSurface to a “local” copy, like even the myRGB = p.RGBSurface, (or even just check the Pixel in an If Statement), and then it never release the Picture references. This referencing of the RGBSurface is enough to create in memory a Object Reference to the Picture you can never release.
My picture add about 25MB per picture to the memory. OSX Console, El Capitan, etc. The way my code turned out, I was creating and additional 65,000 references per additional image in the original code.
I could live with your solution in the meantime, but I think this is really a BUG.