iOS - Memory Issue with Dynamic Texture2D [Paid]
Hello,
I'm having an issue with managing my memory when messing around with dynamic texture2Ds. I'm building a mobile app that has an image editor in it.
The user basically takes a photo using the device camera. This image is then cropped and resized to 512 x 512.
The image then goes through a simple pixel adjustment modifier - which basically duplicates the image 15 times, each with a different colour scheme. The user then selects 1 of the 15 images to keep.
Once this process is done, I destroy all images but the one selected, but my memory isn't cleared up that much.
I've had a look around the internet, and it seems iOS is pretty hard to memory manage with dynamic assets.
So what I've done to remove the textures is this:
var ob = FindObjectsOfType (Texture2D);
for (var t : Texture2D in ob){
if(NeedToKeep(t) == false)
DestroyImmediate(t, true);
}
So this searches the entire project for active loaded Texture2Ds, and destroys them if not needed (destroys all textures but the one the user selected).
I then do this:
System.GC.Collect();
Resources.UnloadUnusedAssets();
So initially, the app uses 30Mb of Memory, which is normal at this point.
With the image taken, the memory jumps to 95Mb of Memory.
The image adjustment (duplication of 15) takes place with the memory jumping to 175Mb of Memory, bearing in mind that the images are only (512x512) x 15 duplications.
Once the image is selected, it does my memory clean - memory goes back down to 140Mbs, which is lower ... but nothing compared to the start. I should only have ONE image loaded in memory which is 512x512. It can't be taking up 110Mbs of Memory? Surely?
Please advise, thanks.
---- Additional ----
When I do a complete memory clean - removal ALL images in memory, the memory goes down to 95Mbs. So now there should be no images in memory, just like it started. Yet it's still no where near the 30Mbs from start.
Why is this? This is becoming a serious issue as it causes my App to crash after a couple of uses.
Have you verified FindObjectsOfType (Texture2D)
is giving you the textures? The docs suggest it doesn't return textures.
@ brianturner : It's defiantly giving me something, it's printing the names of each texture, and then I destroy them. If I do the search again, they do not show on the console, so they're defiantly being removed, just not from the iOS memory.