Generating high numbers of Texture objects - Memory overload

Hi all!

I have read a few forum posts where people are complaining about their texture numbers crashing their mobile app due to memory limitations (RAM). The answer seems to be to use Resource.Load ~. That is all very well, however, in my application, I’m generating the image myself (like a screenshot), and storing that image in a List of Texture2D objects. Then when the user wishes to see them, they can be called on and “enlarged”.

The problem is, once I reach a specific number of theses shots, the mobile force quits the application because of what I assume is memory issues (120 textures for Android - about 30 for iOS).

Would anybody have any ideas on how to manage my Textures so they will somehow load out of RAM, or can I save them externally somehow, then call on them when needed?

Thanks!

Well, you can’t take things out of RAM without storing them, it’s just how computers work. Data takes up memory, and RAM is the memory you have available to you.

So storing to disk, and deleting them from RAM would work. But this has downsides:

  1. loading them back into memory will be slower, so be ready to have that load time.

  2. disk space may be limited, or in the case of cellphones, barrred from access.

Cell phones usually have a limited amount of storage, just like it’s limited in RAM, so users might not want your app filling its storage with tons of images. Are you going to clean these images up? How many images are you going to store?

Oh, and as for the limit in number of textures. It’s really dependent more on how much memory the device has in total, how much memory the OS allows your application to utilize, and how large your images are. So that 120, and 30, textures each is really just a single use case specific to whatever environment you happen to have been running in at that time.

If you don’t need to display all of them at once, you can usually come up with a loading scheme to hide the load times (Resources has Async versions of Load for this purpose).

Resources can be unloaded with Resources.UnloadAsset(object assetToUnload) if you have a specific texture you want to unload and nothing is currently using it (or the last thing using it is about to be manually destroyed/recycled).

You can also use Resources.UnloadUnusedAssets() to unload every currently loaded but unused assets (they’re still eating up memory). I believe this may also work for dynamically loaded assets if they’re not referenced and the GC hasn’t run yet. The normal Resources.Unload() may have this property as well, haven’t tested it in a while.

There are other ways of masking the load times (I’ve used WWW from a temp cache + threading to hide image loading on a mobile app).