Object pooling long list of icons - Loading/unloading textures
I'm working with a game that gets deployed to Android and iOS. We are currently using Unity 5.5.4.
\n
I'm creating a main lobby with a list of about 80 or so icons. Each icon having its own unique image on it. I want to use object pooling so that there are only 10-15 icon gameobjects at once. Existing gameobjects will be re-positioned and the scroll rect will be adjusted so that scrolling will be seamless. I have that part done and working great.
\n
My issue is with loading and unloaded the textures from the asset bundle. We've had issues in the past with Texture2Ds sticking around in memory unless we frequently call Resources.UnloadUnusedAssets() (which seems janky), and even then, some Texture2Ds will stick around in memory. We have our own asset system that manages everything, and it works pretty well, but isn't perfect obviously. Our system doesn't really handle what I want it to do in this situation, so I'm bypassing our system and loading the asset bundle myself and grabbing the assets I need.
\n
Right now, all images are stored as PNGs in the bundle. I load the bundle, then as my layout manager requests an icon (newly instantiated or reused), I call LoadAsset() and it returns a Texture2D. I cast this to a Texture and set it to my RawImage component on the Icon gameobject. While profiling in editor, all of the textures that were used but are now off-screen are still in memory and do not go away. The code is simple and I know for a fact there is nothing referencing them (profiler even reads a 0 count).
\n
Is there a better way to load these images? Or am I managing them wrong? I thought about managing a list of Texture2Ds and trying to stream the images from the bundle into the already allocated Texture2D with LoadRawTextureData(), but I'm not quite sure how I'd do that.
*PS: sorry for poor formatting, couldn't figure out how to add a line spacing...