"Hard-reload" an image?

I’m trying to make a painter function, and I’m working on the eraser function. I want to modify an image to use as mask, making changes to the mask works as a charm, but for performance reasons, I want to reload the mask image as a display object. But it seems that Corona does not actually reload the image after it has been loaded the second time.

Is it possible to remove an image from the memory, to make corona forget it has ever been loaded? [import]uid: 140666 topic_id: 29597 reply_id: 329597[/import]

I believe removing an image and setting it as nil *should* do this, or is that what you are doing and having issues with it? Let me know and will test on my end. [import]uid: 52491 topic_id: 29597 reply_id: 118858[/import]

I thought that would solve the problem too, but it doesn’t, I made a little code to illustrate the problem:
Try toggle the comments between “<><><>”, When you save/load it the second time with another path, it reloads the image, but not when I save/load the same path again.
[lua] --Put this code inside createScene
local sceneView = self.view
local rect1 = display.newRect(sceneView, 200, 200, 100, 100)
rect1:setFillColor(255, 0, 0)
display.save (sceneView, “myImage.jpg”, system.TemporaryDirectory)
loadedImage = display.newImage(sceneView, “myImage.jpg”, system.TemporaryDirectory)
loadedImage.x = 200
loadedImage.y = 400
–<><><><><><><><><><><><><><><><><><><><><>–
display.save (sceneView, “myImage.jpg”, system.TemporaryDirectory)
loadedImage:removeSelf()
loadedImage = nil
loadedImage2 = display.newImage(sceneView, “myImage.jpg”, system.TemporaryDirectory)
loadedImage2.x = 600
loadedImage2.y = 400
–<><><><><><><><><><><><><><><><><><><><><>–
–<><><><><><><><><><><><><><><><><><><><><>–
– display.save (sceneView, “myImage2.jpg”, system.TemporaryDirectory)
– loadedImage:removeSelf()
– loadedImage = nil
– loadedImage2 = display.newImage(sceneView, “myImage2.jpg”, system.TemporaryDirectory)
– loadedImage2.x = 600
– loadedImage2.y = 400
–<><><><><><><><><><><><><><><><><><><><><>–[/lua] [import]uid: 140666 topic_id: 29597 reply_id: 118995[/import]

That’s very useful code, shows issue clearly - would you mind filing a bug report and including this sample to run, please? [import]uid: 52491 topic_id: 29597 reply_id: 119030[/import]

I reported the bug (case #16469). When I tried this code on device (ipad 2), it didn’t seem to load the image the second time at all. It didn’t seem to matter which code I used, the one with the same path and the one with different path both just showed a single rect on screen…
[import]uid: 140666 topic_id: 29597 reply_id: 119093[/import]

Any news about that problem?

Found the solution. After removing the image and setting its variable to nil, I needed to collect garbage. Now the reload works normally

It seems that generally garbage collector kicks is in in periods - to ilustrate it I created graph to check memory usage periodically and what I got was wavey form. When adding collectgarbage () before each check, the graph was straight line. It needs to be emphasissd that nothing was execuded/created during graph ploting.

Any news about that problem?

Found the solution. After removing the image and setting its variable to nil, I needed to collect garbage. Now the reload works normally

It seems that generally garbage collector kicks is in in periods - to ilustrate it I created graph to check memory usage periodically and what I got was wavey form. When adding collectgarbage () before each check, the graph was straight line. It needs to be emphasissd that nothing was execuded/created during graph ploting.